func (c RedisCache) Delete(key string) error { conn := c.pool.Get() defer conn.Close() existed, err := redis.Bool(conn.Do("DEL", key)) if err == nil && !existed { err = ErrCacheMiss } return err }
// check cache's existence in redis. func (rc *RedisCache) IsExist(key string) bool { v, err := redis.Bool(rc.do("EXISTS", key)) if err != nil { return false } if v == false { if _, err = rc.do("HDEL", rc.key, key); err != nil { return false } } return v }
func ExampleBool() { c, err := dial() if err != nil { fmt.Println(err) return } defer c.Close() c.Do("SET", "foo", 1) exists, _ := redis.Bool(c.Do("EXISTS", "foo")) fmt.Printf("%#v\n", exists) // Output: // true }
// decrease counter in redis. func (rc *RedisCache) Decr(key string) error { _, err := redis.Bool(rc.do("INCRBY", key, -1)) return err }
func exists(conn redis.Conn, key string) (bool, error) { return redis.Bool(conn.Do("EXISTS", key)) }