diff --git a/commands.go b/commands.go index b21a8ee..f84311c 100644 --- a/commands.go +++ b/commands.go @@ -61,7 +61,7 @@ type statefulCmdable struct { //------------------------------------------------------------------------------ -func (c statefulCmdable) Auth(password string) *StatusCmd { +func (c *statefulCmdable) Auth(password string) *StatusCmd { cmd := NewStatusCmd("auth", password) c.process(cmd) return cmd @@ -79,11 +79,11 @@ func (c *cmdable) Ping() *StatusCmd { return cmd } -func (c cmdable) Quit() *StatusCmd { +func (c *cmdable) Quit() *StatusCmd { panic("not implemented") } -func (c statefulCmdable) Select(index int) *StatusCmd { +func (c *statefulCmdable) Select(index int) *StatusCmd { cmd := NewStatusCmd("select", index) c.process(cmd) return cmd @@ -91,7 +91,7 @@ func (c statefulCmdable) Select(index int) *StatusCmd { //------------------------------------------------------------------------------ -func (c cmdable) Del(keys ...string) *IntCmd { +func (c *cmdable) Del(keys ...string) *IntCmd { args := make([]interface{}, 1+len(keys)) args[0] = "DEL" for i, key := range keys { @@ -102,37 +102,37 @@ func (c cmdable) Del(keys ...string) *IntCmd { return cmd } -func (c cmdable) Dump(key string) *StringCmd { +func (c *cmdable) Dump(key string) *StringCmd { cmd := NewStringCmd("dump", key) c.process(cmd) return cmd } -func (c cmdable) Exists(key string) *BoolCmd { +func (c *cmdable) Exists(key string) *BoolCmd { cmd := NewBoolCmd("exists", key) c.process(cmd) return cmd } -func (c cmdable) Expire(key string, expiration time.Duration) *BoolCmd { +func (c *cmdable) Expire(key string, expiration time.Duration) *BoolCmd { cmd := NewBoolCmd("expire", key, formatSec(expiration)) c.process(cmd) return cmd } -func (c cmdable) ExpireAt(key string, tm time.Time) *BoolCmd { +func (c *cmdable) ExpireAt(key string, tm time.Time) *BoolCmd { cmd := NewBoolCmd("expireat", key, tm.Unix()) c.process(cmd) return cmd } -func (c cmdable) Keys(pattern string) *StringSliceCmd { +func (c *cmdable) Keys(pattern string) *StringSliceCmd { cmd := NewStringSliceCmd("keys", pattern) c.process(cmd) return cmd } -func (c cmdable) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd { +func (c *cmdable) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd { cmd := NewStatusCmd( "migrate", host, @@ -146,13 +146,13 @@ func (c cmdable) Migrate(host, port, key string, db int64, timeout time.Duration return cmd } -func (c cmdable) Move(key string, db int64) *BoolCmd { +func (c *cmdable) Move(key string, db int64) *BoolCmd { cmd := NewBoolCmd("move", key, db) c.process(cmd) return cmd } -func (c cmdable) ObjectRefCount(keys ...string) *IntCmd { +func (c *cmdable) ObjectRefCount(keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "refcount" @@ -164,7 +164,7 @@ func (c cmdable) ObjectRefCount(keys ...string) *IntCmd { return cmd } -func (c cmdable) ObjectEncoding(keys ...string) *StringCmd { +func (c *cmdable) ObjectEncoding(keys ...string) *StringCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "encoding" @@ -176,7 +176,7 @@ func (c cmdable) ObjectEncoding(keys ...string) *StringCmd { return cmd } -func (c cmdable) ObjectIdleTime(keys ...string) *DurationCmd { +func (c *cmdable) ObjectIdleTime(keys ...string) *DurationCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "idletime" @@ -188,19 +188,19 @@ func (c cmdable) ObjectIdleTime(keys ...string) *DurationCmd { return cmd } -func (c cmdable) Persist(key string) *BoolCmd { +func (c *cmdable) Persist(key string) *BoolCmd { cmd := NewBoolCmd("persist", key) c.process(cmd) return cmd } -func (c cmdable) PExpire(key string, expiration time.Duration) *BoolCmd { +func (c *cmdable) PExpire(key string, expiration time.Duration) *BoolCmd { cmd := NewBoolCmd("pexpire", key, formatMs(expiration)) c.process(cmd) return cmd } -func (c cmdable) PExpireAt(key string, tm time.Time) *BoolCmd { +func (c *cmdable) PExpireAt(key string, tm time.Time) *BoolCmd { cmd := NewBoolCmd( "pexpireat", key, @@ -210,31 +210,31 @@ func (c cmdable) PExpireAt(key string, tm time.Time) *BoolCmd { return cmd } -func (c cmdable) PTTL(key string) *DurationCmd { +func (c *cmdable) PTTL(key string) *DurationCmd { cmd := NewDurationCmd(time.Millisecond, "pttl", key) c.process(cmd) return cmd } -func (c cmdable) RandomKey() *StringCmd { +func (c *cmdable) RandomKey() *StringCmd { cmd := NewStringCmd("randomkey") c.process(cmd) return cmd } -func (c cmdable) Rename(key, newkey string) *StatusCmd { +func (c *cmdable) Rename(key, newkey string) *StatusCmd { cmd := NewStatusCmd("rename", key, newkey) c.process(cmd) return cmd } -func (c cmdable) RenameNX(key, newkey string) *BoolCmd { +func (c *cmdable) RenameNX(key, newkey string) *BoolCmd { cmd := NewBoolCmd("renamenx", key, newkey) c.process(cmd) return cmd } -func (c cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd { +func (c *cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd { cmd := NewStatusCmd( "restore", key, @@ -245,7 +245,7 @@ func (c cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd return cmd } -func (c cmdable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd { +func (c *cmdable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd { cmd := NewStatusCmd( "restore", key, @@ -289,31 +289,31 @@ func (sort *Sort) args(key string) []interface{} { return args } -func (c cmdable) Sort(key string, sort Sort) *StringSliceCmd { +func (c *cmdable) Sort(key string, sort Sort) *StringSliceCmd { cmd := NewStringSliceCmd(sort.args(key)...) c.process(cmd) return cmd } -func (c cmdable) SortInterfaces(key string, sort Sort) *SliceCmd { +func (c *cmdable) SortInterfaces(key string, sort Sort) *SliceCmd { cmd := NewSliceCmd(sort.args(key)...) c.process(cmd) return cmd } -func (c cmdable) TTL(key string) *DurationCmd { +func (c *cmdable) TTL(key string) *DurationCmd { cmd := NewDurationCmd(time.Second, "ttl", key) c.process(cmd) return cmd } -func (c cmdable) Type(key string) *StatusCmd { +func (c *cmdable) Type(key string) *StatusCmd { cmd := NewStatusCmd("type", key) c.process(cmd) return cmd } -func (c cmdable) Scan(cursor uint64, match string, count int64) Scanner { +func (c *cmdable) Scan(cursor uint64, match string, count int64) Scanner { args := []interface{}{"scan", cursor} if match != "" { args = append(args, "match", match) @@ -329,7 +329,7 @@ func (c cmdable) Scan(cursor uint64, match string, count int64) Scanner { } } -func (c cmdable) SScan(key string, cursor uint64, match string, count int64) Scanner { +func (c *cmdable) SScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"sscan", key, cursor} if match != "" { args = append(args, "match", match) @@ -345,7 +345,7 @@ func (c cmdable) SScan(key string, cursor uint64, match string, count int64) Sca } } -func (c cmdable) HScan(key string, cursor uint64, match string, count int64) Scanner { +func (c *cmdable) HScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"hscan", key, cursor} if match != "" { args = append(args, "match", match) @@ -361,7 +361,7 @@ func (c cmdable) HScan(key string, cursor uint64, match string, count int64) Sca } } -func (c cmdable) ZScan(key string, cursor uint64, match string, count int64) Scanner { +func (c *cmdable) ZScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"zscan", key, cursor} if match != "" { args = append(args, "match", match) @@ -379,7 +379,7 @@ func (c cmdable) ZScan(key string, cursor uint64, match string, count int64) Sca //------------------------------------------------------------------------------ -func (c cmdable) Append(key, value string) *IntCmd { +func (c *cmdable) Append(key, value string) *IntCmd { cmd := NewIntCmd("append", key, value) c.process(cmd) return cmd @@ -389,7 +389,7 @@ type BitCount struct { Start, End int64 } -func (c cmdable) BitCount(key string, bitCount *BitCount) *IntCmd { +func (c *cmdable) BitCount(key string, bitCount *BitCount) *IntCmd { args := []interface{}{"bitcount", key} if bitCount != nil { args = append( @@ -403,7 +403,7 @@ func (c cmdable) BitCount(key string, bitCount *BitCount) *IntCmd { return cmd } -func (c cmdable) bitOp(op, destKey string, keys ...string) *IntCmd { +func (c *cmdable) bitOp(op, destKey string, keys ...string) *IntCmd { args := make([]interface{}, 3+len(keys)) args[0] = "bitop" args[1] = op @@ -416,23 +416,23 @@ func (c cmdable) bitOp(op, destKey string, keys ...string) *IntCmd { return cmd } -func (c cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd { +func (c *cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd { return c.bitOp("and", destKey, keys...) } -func (c cmdable) BitOpOr(destKey string, keys ...string) *IntCmd { +func (c *cmdable) BitOpOr(destKey string, keys ...string) *IntCmd { return c.bitOp("or", destKey, keys...) } -func (c cmdable) BitOpXor(destKey string, keys ...string) *IntCmd { +func (c *cmdable) BitOpXor(destKey string, keys ...string) *IntCmd { return c.bitOp("xor", destKey, keys...) } -func (c cmdable) BitOpNot(destKey string, key string) *IntCmd { +func (c *cmdable) BitOpNot(destKey string, key string) *IntCmd { return c.bitOp("not", destKey, key) } -func (c cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd { +func (c *cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd { args := make([]interface{}, 3+len(pos)) args[0] = "bitpos" args[1] = key @@ -452,61 +452,61 @@ func (c cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd { return cmd } -func (c cmdable) Decr(key string) *IntCmd { +func (c *cmdable) Decr(key string) *IntCmd { cmd := NewIntCmd("decr", key) c.process(cmd) return cmd } -func (c cmdable) DecrBy(key string, decrement int64) *IntCmd { +func (c *cmdable) DecrBy(key string, decrement int64) *IntCmd { cmd := NewIntCmd("decrby", key, decrement) c.process(cmd) return cmd } -func (c cmdable) Get(key string) *StringCmd { +func (c *cmdable) Get(key string) *StringCmd { cmd := NewStringCmd("get", key) c.process(cmd) return cmd } -func (c cmdable) GetBit(key string, offset int64) *IntCmd { +func (c *cmdable) GetBit(key string, offset int64) *IntCmd { cmd := NewIntCmd("getbit", key, offset) c.process(cmd) return cmd } -func (c cmdable) GetRange(key string, start, end int64) *StringCmd { +func (c *cmdable) GetRange(key string, start, end int64) *StringCmd { cmd := NewStringCmd("getrange", key, start, end) c.process(cmd) return cmd } -func (c cmdable) GetSet(key string, value interface{}) *StringCmd { +func (c *cmdable) GetSet(key string, value interface{}) *StringCmd { cmd := NewStringCmd("getset", key, value) c.process(cmd) return cmd } -func (c cmdable) Incr(key string) *IntCmd { +func (c *cmdable) Incr(key string) *IntCmd { cmd := NewIntCmd("incr", key) c.process(cmd) return cmd } -func (c cmdable) IncrBy(key string, value int64) *IntCmd { +func (c *cmdable) IncrBy(key string, value int64) *IntCmd { cmd := NewIntCmd("incrby", key, value) c.process(cmd) return cmd } -func (c cmdable) IncrByFloat(key string, value float64) *FloatCmd { +func (c *cmdable) IncrByFloat(key string, value float64) *FloatCmd { cmd := NewFloatCmd("incrbyfloat", key, value) c.process(cmd) return cmd } -func (c cmdable) MGet(keys ...string) *SliceCmd { +func (c *cmdable) MGet(keys ...string) *SliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "mget" for i, key := range keys { @@ -517,7 +517,7 @@ func (c cmdable) MGet(keys ...string) *SliceCmd { return cmd } -func (c cmdable) MSet(pairs ...interface{}) *StatusCmd { +func (c *cmdable) MSet(pairs ...interface{}) *StatusCmd { args := make([]interface{}, 1+len(pairs)) args[0] = "mset" for i, pair := range pairs { @@ -528,7 +528,7 @@ func (c cmdable) MSet(pairs ...interface{}) *StatusCmd { return cmd } -func (c cmdable) MSetNX(pairs ...interface{}) *BoolCmd { +func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd { args := make([]interface{}, 1+len(pairs)) args[0] = "msetnx" for i, pair := range pairs { @@ -542,7 +542,7 @@ func (c cmdable) MSetNX(pairs ...interface{}) *BoolCmd { // Redis `SET key value [expiration]` command. // // Zero expiration means the key has no expiration time. -func (c cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd { +func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd { args := make([]interface{}, 3, 4) args[0] = "set" args[1] = key @@ -559,7 +559,7 @@ func (c cmdable) Set(key string, value interface{}, expiration time.Duration) *S return cmd } -func (c cmdable) SetBit(key string, offset int64, value int) *IntCmd { +func (c *cmdable) SetBit(key string, offset int64, value int) *IntCmd { cmd := NewIntCmd( "SETBIT", key, @@ -573,7 +573,7 @@ func (c cmdable) SetBit(key string, offset int64, value int) *IntCmd { // Redis `SET key value [expiration] NX` command. // // Zero expiration means the key has no expiration time. -func (c cmdable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd { +func (c *cmdable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd { var cmd *BoolCmd if expiration == 0 { // Use old `SETNX` to support old Redis versions. @@ -592,7 +592,7 @@ func (c cmdable) SetNX(key string, value interface{}, expiration time.Duration) // Redis `SET key value [expiration] XX` command. // // Zero expiration means the key has no expiration time. -func (c cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd { +func (c *cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd { var cmd *BoolCmd if usePrecise(expiration) { cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx") @@ -603,13 +603,13 @@ func (c cmdable) SetXX(key string, value interface{}, expiration time.Duration) return cmd } -func (c cmdable) SetRange(key string, offset int64, value string) *IntCmd { +func (c *cmdable) SetRange(key string, offset int64, value string) *IntCmd { cmd := NewIntCmd("setrange", key, offset, value) c.process(cmd) return cmd } -func (c cmdable) StrLen(key string) *IntCmd { +func (c *cmdable) StrLen(key string) *IntCmd { cmd := NewIntCmd("strlen", key) c.process(cmd) return cmd @@ -617,7 +617,7 @@ func (c cmdable) StrLen(key string) *IntCmd { //------------------------------------------------------------------------------ -func (c cmdable) HDel(key string, fields ...string) *IntCmd { +func (c *cmdable) HDel(key string, fields ...string) *IntCmd { args := make([]interface{}, 2+len(fields)) args[0] = "hdel" args[1] = key @@ -629,49 +629,49 @@ func (c cmdable) HDel(key string, fields ...string) *IntCmd { return cmd } -func (c cmdable) HExists(key, field string) *BoolCmd { +func (c *cmdable) HExists(key, field string) *BoolCmd { cmd := NewBoolCmd("hexists", key, field) c.process(cmd) return cmd } -func (c cmdable) HGet(key, field string) *StringCmd { +func (c *cmdable) HGet(key, field string) *StringCmd { cmd := NewStringCmd("hget", key, field) c.process(cmd) return cmd } -func (c cmdable) HGetAll(key string) *StringStringMapCmd { +func (c *cmdable) HGetAll(key string) *StringStringMapCmd { cmd := NewStringStringMapCmd("hgetall", key) c.process(cmd) return cmd } -func (c cmdable) HIncrBy(key, field string, incr int64) *IntCmd { +func (c *cmdable) HIncrBy(key, field string, incr int64) *IntCmd { cmd := NewIntCmd("hincrby", key, field, incr) c.process(cmd) return cmd } -func (c cmdable) HIncrByFloat(key, field string, incr float64) *FloatCmd { +func (c *cmdable) HIncrByFloat(key, field string, incr float64) *FloatCmd { cmd := NewFloatCmd("hincrbyfloat", key, field, incr) c.process(cmd) return cmd } -func (c cmdable) HKeys(key string) *StringSliceCmd { +func (c *cmdable) HKeys(key string) *StringSliceCmd { cmd := NewStringSliceCmd("hkeys", key) c.process(cmd) return cmd } -func (c cmdable) HLen(key string) *IntCmd { +func (c *cmdable) HLen(key string) *IntCmd { cmd := NewIntCmd("hlen", key) c.process(cmd) return cmd } -func (c cmdable) HMGet(key string, fields ...string) *SliceCmd { +func (c *cmdable) HMGet(key string, fields ...string) *SliceCmd { args := make([]interface{}, 2+len(fields)) args[0] = "hmget" args[1] = key @@ -683,7 +683,7 @@ func (c cmdable) HMGet(key string, fields ...string) *SliceCmd { return cmd } -func (c cmdable) HMSet(key string, fields map[string]string) *StatusCmd { +func (c *cmdable) HMSet(key string, fields map[string]string) *StatusCmd { args := make([]interface{}, 2+len(fields)*2) args[0] = "hmset" args[1] = key @@ -698,19 +698,19 @@ func (c cmdable) HMSet(key string, fields map[string]string) *StatusCmd { return cmd } -func (c cmdable) HSet(key, field, value string) *BoolCmd { +func (c *cmdable) HSet(key, field, value string) *BoolCmd { cmd := NewBoolCmd("hset", key, field, value) c.process(cmd) return cmd } -func (c cmdable) HSetNX(key, field, value string) *BoolCmd { +func (c *cmdable) HSetNX(key, field, value string) *BoolCmd { cmd := NewBoolCmd("hsetnx", key, field, value) c.process(cmd) return cmd } -func (c cmdable) HVals(key string) *StringSliceCmd { +func (c *cmdable) HVals(key string) *StringSliceCmd { cmd := NewStringSliceCmd("hvals", key) c.process(cmd) return cmd @@ -718,7 +718,7 @@ func (c cmdable) HVals(key string) *StringSliceCmd { //------------------------------------------------------------------------------ -func (c cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd { +func (c *cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)+1) args[0] = "blpop" for i, key := range keys { @@ -731,7 +731,7 @@ func (c cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd { return cmd } -func (c cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd { +func (c *cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)+1) args[0] = "brpop" for i, key := range keys { @@ -744,7 +744,7 @@ func (c cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd { return cmd } -func (c cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd { +func (c *cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd { cmd := NewStringCmd( "brpoplpush", source, @@ -756,43 +756,43 @@ func (c cmdable) BRPopLPush(source, destination string, timeout time.Duration) * return cmd } -func (c cmdable) LIndex(key string, index int64) *StringCmd { +func (c *cmdable) LIndex(key string, index int64) *StringCmd { cmd := NewStringCmd("lindex", key, index) c.process(cmd) return cmd } -func (c cmdable) LInsert(key, op string, pivot, value interface{}) *IntCmd { +func (c *cmdable) LInsert(key, op string, pivot, value interface{}) *IntCmd { cmd := NewIntCmd("linsert", key, op, pivot, value) c.process(cmd) return cmd } -func (c cmdable) LInsertBefore(key string, pivot, value interface{}) *IntCmd { +func (c *cmdable) LInsertBefore(key string, pivot, value interface{}) *IntCmd { cmd := NewIntCmd("linsert", key, "before", pivot, value) c.process(cmd) return cmd } -func (c cmdable) LInsertAfter(key string, pivot, value interface{}) *IntCmd { +func (c *cmdable) LInsertAfter(key string, pivot, value interface{}) *IntCmd { cmd := NewIntCmd("linsert", key, "after", pivot, value) c.process(cmd) return cmd } -func (c cmdable) LLen(key string) *IntCmd { +func (c *cmdable) LLen(key string) *IntCmd { cmd := NewIntCmd("llen", key) c.process(cmd) return cmd } -func (c cmdable) LPop(key string) *StringCmd { +func (c *cmdable) LPop(key string) *StringCmd { cmd := NewStringCmd("lpop", key) c.process(cmd) return cmd } -func (c cmdable) LPush(key string, values ...interface{}) *IntCmd { +func (c *cmdable) LPush(key string, values ...interface{}) *IntCmd { args := make([]interface{}, 2+len(values)) args[0] = "lpush" args[1] = key @@ -804,13 +804,13 @@ func (c cmdable) LPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) LPushX(key string, value interface{}) *IntCmd { +func (c *cmdable) LPushX(key string, value interface{}) *IntCmd { cmd := NewIntCmd("lpushx", key, value) c.process(cmd) return cmd } -func (c cmdable) LRange(key string, start, stop int64) *StringSliceCmd { +func (c *cmdable) LRange(key string, start, stop int64) *StringSliceCmd { cmd := NewStringSliceCmd( "lrange", key, @@ -821,19 +821,19 @@ func (c cmdable) LRange(key string, start, stop int64) *StringSliceCmd { return cmd } -func (c cmdable) LRem(key string, count int64, value interface{}) *IntCmd { +func (c *cmdable) LRem(key string, count int64, value interface{}) *IntCmd { cmd := NewIntCmd("lrem", key, count, value) c.process(cmd) return cmd } -func (c cmdable) LSet(key string, index int64, value interface{}) *StatusCmd { +func (c *cmdable) LSet(key string, index int64, value interface{}) *StatusCmd { cmd := NewStatusCmd("lset", key, index, value) c.process(cmd) return cmd } -func (c cmdable) LTrim(key string, start, stop int64) *StatusCmd { +func (c *cmdable) LTrim(key string, start, stop int64) *StatusCmd { cmd := NewStatusCmd( "ltrim", key, @@ -844,19 +844,19 @@ func (c cmdable) LTrim(key string, start, stop int64) *StatusCmd { return cmd } -func (c cmdable) RPop(key string) *StringCmd { +func (c *cmdable) RPop(key string) *StringCmd { cmd := NewStringCmd("rpop", key) c.process(cmd) return cmd } -func (c cmdable) RPopLPush(source, destination string) *StringCmd { +func (c *cmdable) RPopLPush(source, destination string) *StringCmd { cmd := NewStringCmd("rpoplpush", source, destination) c.process(cmd) return cmd } -func (c cmdable) RPush(key string, values ...interface{}) *IntCmd { +func (c *cmdable) RPush(key string, values ...interface{}) *IntCmd { args := make([]interface{}, 2+len(values)) args[0] = "rpush" args[1] = key @@ -868,7 +868,7 @@ func (c cmdable) RPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) RPushX(key string, value interface{}) *IntCmd { +func (c *cmdable) RPushX(key string, value interface{}) *IntCmd { cmd := NewIntCmd("rpushx", key, value) c.process(cmd) return cmd @@ -876,7 +876,7 @@ func (c cmdable) RPushX(key string, value interface{}) *IntCmd { //------------------------------------------------------------------------------ -func (c cmdable) SAdd(key string, members ...interface{}) *IntCmd { +func (c *cmdable) SAdd(key string, members ...interface{}) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "sadd" args[1] = key @@ -888,13 +888,13 @@ func (c cmdable) SAdd(key string, members ...interface{}) *IntCmd { return cmd } -func (c cmdable) SCard(key string) *IntCmd { +func (c *cmdable) SCard(key string) *IntCmd { cmd := NewIntCmd("scard", key) c.process(cmd) return cmd } -func (c cmdable) SDiff(keys ...string) *StringSliceCmd { +func (c *cmdable) SDiff(keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sdiff" for i, key := range keys { @@ -905,7 +905,7 @@ func (c cmdable) SDiff(keys ...string) *StringSliceCmd { return cmd } -func (c cmdable) SDiffStore(destination string, keys ...string) *IntCmd { +func (c *cmdable) SDiffStore(destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sdiffstore" args[1] = destination @@ -917,7 +917,7 @@ func (c cmdable) SDiffStore(destination string, keys ...string) *IntCmd { return cmd } -func (c cmdable) SInter(keys ...string) *StringSliceCmd { +func (c *cmdable) SInter(keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sinter" for i, key := range keys { @@ -928,7 +928,7 @@ func (c cmdable) SInter(keys ...string) *StringSliceCmd { return cmd } -func (c cmdable) SInterStore(destination string, keys ...string) *IntCmd { +func (c *cmdable) SInterStore(destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sinterstore" args[1] = destination @@ -940,53 +940,53 @@ func (c cmdable) SInterStore(destination string, keys ...string) *IntCmd { return cmd } -func (c cmdable) SIsMember(key string, member interface{}) *BoolCmd { +func (c *cmdable) SIsMember(key string, member interface{}) *BoolCmd { cmd := NewBoolCmd("sismember", key, member) c.process(cmd) return cmd } -func (c cmdable) SMembers(key string) *StringSliceCmd { +func (c *cmdable) SMembers(key string) *StringSliceCmd { cmd := NewStringSliceCmd("smembers", key) c.process(cmd) return cmd } -func (c cmdable) SMove(source, destination string, member interface{}) *BoolCmd { +func (c *cmdable) SMove(source, destination string, member interface{}) *BoolCmd { cmd := NewBoolCmd("smove", source, destination, member) c.process(cmd) return cmd } // Redis `SPOP key` command. -func (c cmdable) SPop(key string) *StringCmd { +func (c *cmdable) SPop(key string) *StringCmd { cmd := NewStringCmd("spop", key) c.process(cmd) return cmd } // Redis `SPOP key count` command. -func (c cmdable) SPopN(key string, count int64) *StringSliceCmd { +func (c *cmdable) SPopN(key string, count int64) *StringSliceCmd { cmd := NewStringSliceCmd("spop", key, count) c.process(cmd) return cmd } // Redis `SRANDMEMBER key` command. -func (c cmdable) SRandMember(key string) *StringCmd { +func (c *cmdable) SRandMember(key string) *StringCmd { cmd := NewStringCmd("srandmember", key) c.process(cmd) return cmd } // Redis `SRANDMEMBER key count` command. -func (c cmdable) SRandMemberN(key string, count int64) *StringSliceCmd { +func (c *cmdable) SRandMemberN(key string, count int64) *StringSliceCmd { cmd := NewStringSliceCmd("srandmember", key, count) c.process(cmd) return cmd } -func (c cmdable) SRem(key string, members ...interface{}) *IntCmd { +func (c *cmdable) SRem(key string, members ...interface{}) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "srem" args[1] = key @@ -998,7 +998,7 @@ func (c cmdable) SRem(key string, members ...interface{}) *IntCmd { return cmd } -func (c cmdable) SUnion(keys ...string) *StringSliceCmd { +func (c *cmdable) SUnion(keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sunion" for i, key := range keys { @@ -1009,7 +1009,7 @@ func (c cmdable) SUnion(keys ...string) *StringSliceCmd { return cmd } -func (c cmdable) SUnionStore(destination string, keys ...string) *IntCmd { +func (c *cmdable) SUnionStore(destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sunionstore" args[1] = destination @@ -1036,7 +1036,7 @@ type ZStore struct { Aggregate string } -func (c cmdable) zAdd(a []interface{}, n int, members ...Z) *IntCmd { +func (c *cmdable) zAdd(a []interface{}, n int, members ...Z) *IntCmd { for i, m := range members { a[n+2*i] = m.Score a[n+2*i+1] = m.Member @@ -1047,7 +1047,7 @@ func (c cmdable) zAdd(a []interface{}, n int, members ...Z) *IntCmd { } // Redis `ZADD key score member [score member ...]` command. -func (c cmdable) ZAdd(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAdd(key string, members ...Z) *IntCmd { const n = 2 a := make([]interface{}, n+2*len(members)) a[0], a[1] = "zadd", key @@ -1055,7 +1055,7 @@ func (c cmdable) ZAdd(key string, members ...Z) *IntCmd { } // Redis `ZADD key NX score member [score member ...]` command. -func (c cmdable) ZAddNX(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAddNX(key string, members ...Z) *IntCmd { const n = 3 a := make([]interface{}, n+2*len(members)) a[0], a[1], a[2] = "zadd", key, "nx" @@ -1063,7 +1063,7 @@ func (c cmdable) ZAddNX(key string, members ...Z) *IntCmd { } // Redis `ZADD key XX score member [score member ...]` command. -func (c cmdable) ZAddXX(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAddXX(key string, members ...Z) *IntCmd { const n = 3 a := make([]interface{}, n+2*len(members)) a[0], a[1], a[2] = "zadd", key, "xx" @@ -1071,7 +1071,7 @@ func (c cmdable) ZAddXX(key string, members ...Z) *IntCmd { } // Redis `ZADD key CH score member [score member ...]` command. -func (c cmdable) ZAddCh(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAddCh(key string, members ...Z) *IntCmd { const n = 3 a := make([]interface{}, n+2*len(members)) a[0], a[1], a[2] = "zadd", key, "ch" @@ -1079,7 +1079,7 @@ func (c cmdable) ZAddCh(key string, members ...Z) *IntCmd { } // Redis `ZADD key NX CH score member [score member ...]` command. -func (c cmdable) ZAddNXCh(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAddNXCh(key string, members ...Z) *IntCmd { const n = 4 a := make([]interface{}, n+2*len(members)) a[0], a[1], a[2], a[3] = "zadd", key, "nx", "ch" @@ -1087,14 +1087,14 @@ func (c cmdable) ZAddNXCh(key string, members ...Z) *IntCmd { } // Redis `ZADD key XX CH score member [score member ...]` command. -func (c cmdable) ZAddXXCh(key string, members ...Z) *IntCmd { +func (c *cmdable) ZAddXXCh(key string, members ...Z) *IntCmd { const n = 4 a := make([]interface{}, n+2*len(members)) a[0], a[1], a[2], a[3] = "zadd", key, "xx", "ch" return c.zAdd(a, n, members...) } -func (c cmdable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd { +func (c *cmdable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd { for i, m := range members { a[n+2*i] = m.Score a[n+2*i+1] = m.Member @@ -1105,7 +1105,7 @@ func (c cmdable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd { } // Redis `ZADD key INCR score member` command. -func (c cmdable) ZIncr(key string, member Z) *FloatCmd { +func (c *cmdable) ZIncr(key string, member Z) *FloatCmd { const n = 3 a := make([]interface{}, n+2) a[0], a[1], a[2] = "zadd", key, "incr" @@ -1113,7 +1113,7 @@ func (c cmdable) ZIncr(key string, member Z) *FloatCmd { } // Redis `ZADD key NX INCR score member` command. -func (c cmdable) ZIncrNX(key string, member Z) *FloatCmd { +func (c *cmdable) ZIncrNX(key string, member Z) *FloatCmd { const n = 4 a := make([]interface{}, n+2) a[0], a[1], a[2], a[3] = "zadd", key, "incr", "nx" @@ -1121,32 +1121,32 @@ func (c cmdable) ZIncrNX(key string, member Z) *FloatCmd { } // Redis `ZADD key XX INCR score member` command. -func (c cmdable) ZIncrXX(key string, member Z) *FloatCmd { +func (c *cmdable) ZIncrXX(key string, member Z) *FloatCmd { const n = 4 a := make([]interface{}, n+2) a[0], a[1], a[2], a[3] = "zadd", key, "incr", "xx" return c.zIncr(a, n, member) } -func (c cmdable) ZCard(key string) *IntCmd { +func (c *cmdable) ZCard(key string) *IntCmd { cmd := NewIntCmd("zcard", key) c.process(cmd) return cmd } -func (c cmdable) ZCount(key, min, max string) *IntCmd { +func (c *cmdable) ZCount(key, min, max string) *IntCmd { cmd := NewIntCmd("zcount", key, min, max) c.process(cmd) return cmd } -func (c cmdable) ZIncrBy(key string, increment float64, member string) *FloatCmd { +func (c *cmdable) ZIncrBy(key string, increment float64, member string) *FloatCmd { cmd := NewFloatCmd("zincrby", key, increment, member) c.process(cmd) return cmd } -func (c cmdable) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd { +func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd { args := make([]interface{}, 3+len(keys)) args[0] = "zinterstore" args[1] = destination @@ -1168,7 +1168,7 @@ func (c cmdable) ZInterStore(destination string, store ZStore, keys ...string) * return cmd } -func (c cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd { +func (c *cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd { args := []interface{}{ "zrange", key, @@ -1183,11 +1183,11 @@ func (c cmdable) zRange(key string, start, stop int64, withScores bool) *StringS return cmd } -func (c cmdable) ZRange(key string, start, stop int64) *StringSliceCmd { +func (c *cmdable) ZRange(key string, start, stop int64) *StringSliceCmd { return c.zRange(key, start, stop, false) } -func (c cmdable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd { +func (c *cmdable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd { cmd := NewZSliceCmd("zrange", key, start, stop, "withscores") c.process(cmd) return cmd @@ -1198,7 +1198,7 @@ type ZRangeBy struct { Offset, Count int64 } -func (c cmdable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd { +func (c *cmdable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd { args := []interface{}{zcmd, key, opt.Min, opt.Max} if withScores { args = append(args, "withscores") @@ -1216,15 +1216,15 @@ func (c cmdable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *Stri return cmd } -func (c cmdable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { +func (c *cmdable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { return c.zRangeBy("zrangebyscore", key, opt, false) } -func (c cmdable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { +func (c *cmdable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { return c.zRangeBy("zrangebylex", key, opt, false) } -func (c cmdable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { +func (c *cmdable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { args := []interface{}{"zrangebyscore", key, opt.Min, opt.Max, "withscores"} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1239,13 +1239,13 @@ func (c cmdable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { return cmd } -func (c cmdable) ZRank(key, member string) *IntCmd { +func (c *cmdable) ZRank(key, member string) *IntCmd { cmd := NewIntCmd("zrank", key, member) c.process(cmd) return cmd } -func (c cmdable) ZRem(key string, members ...interface{}) *IntCmd { +func (c *cmdable) ZRem(key string, members ...interface{}) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "zrem" args[1] = key @@ -1257,7 +1257,7 @@ func (c cmdable) ZRem(key string, members ...interface{}) *IntCmd { return cmd } -func (c cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd { +func (c *cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd { cmd := NewIntCmd( "zremrangebyrank", key, @@ -1268,25 +1268,25 @@ func (c cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd { return cmd } -func (c cmdable) ZRemRangeByScore(key, min, max string) *IntCmd { +func (c *cmdable) ZRemRangeByScore(key, min, max string) *IntCmd { cmd := NewIntCmd("zremrangebyscore", key, min, max) c.process(cmd) return cmd } -func (c cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd { +func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd { cmd := NewStringSliceCmd("zrevrange", key, start, stop) c.process(cmd) return cmd } -func (c cmdable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd { +func (c *cmdable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd { cmd := NewZSliceCmd("zrevrange", key, start, stop, "withscores") c.process(cmd) return cmd } -func (c cmdable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd { +func (c *cmdable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd { args := []interface{}{zcmd, key, opt.Max, opt.Min} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1301,15 +1301,15 @@ func (c cmdable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd { return cmd } -func (c cmdable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { +func (c *cmdable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { return c.zRevRangeBy("zrevrangebyscore", key, opt) } -func (c cmdable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { +func (c *cmdable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { return c.zRevRangeBy("zrevrangebylex", key, opt) } -func (c cmdable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { +func (c *cmdable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { args := []interface{}{"zrevrangebyscore", key, opt.Max, opt.Min, "withscores"} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1324,19 +1324,19 @@ func (c cmdable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd return cmd } -func (c cmdable) ZRevRank(key, member string) *IntCmd { +func (c *cmdable) ZRevRank(key, member string) *IntCmd { cmd := NewIntCmd("zrevrank", key, member) c.process(cmd) return cmd } -func (c cmdable) ZScore(key, member string) *FloatCmd { +func (c *cmdable) ZScore(key, member string) *FloatCmd { cmd := NewFloatCmd("zscore", key, member) c.process(cmd) return cmd } -func (c cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd { +func (c *cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd { args := make([]interface{}, 3+len(keys)) args[0] = "zunionstore" args[1] = dest @@ -1360,7 +1360,7 @@ func (c cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd //------------------------------------------------------------------------------ -func (c cmdable) PFAdd(key string, els ...interface{}) *IntCmd { +func (c *cmdable) PFAdd(key string, els ...interface{}) *IntCmd { args := make([]interface{}, 2+len(els)) args[0] = "pfadd" args[1] = key @@ -1372,7 +1372,7 @@ func (c cmdable) PFAdd(key string, els ...interface{}) *IntCmd { return cmd } -func (c cmdable) PFCount(keys ...string) *IntCmd { +func (c *cmdable) PFCount(keys ...string) *IntCmd { args := make([]interface{}, 1+len(keys)) args[0] = "pfcount" for i, key := range keys { @@ -1383,7 +1383,7 @@ func (c cmdable) PFCount(keys ...string) *IntCmd { return cmd } -func (c cmdable) PFMerge(dest string, keys ...string) *StatusCmd { +func (c *cmdable) PFMerge(dest string, keys ...string) *StatusCmd { args := make([]interface{}, 2+len(keys)) args[0] = "pfmerge" args[1] = dest @@ -1397,38 +1397,38 @@ func (c cmdable) PFMerge(dest string, keys ...string) *StatusCmd { //------------------------------------------------------------------------------ -func (c cmdable) BgRewriteAOF() *StatusCmd { +func (c *cmdable) BgRewriteAOF() *StatusCmd { cmd := NewStatusCmd("bgrewriteaof") c.process(cmd) return cmd } -func (c cmdable) BgSave() *StatusCmd { +func (c *cmdable) BgSave() *StatusCmd { cmd := NewStatusCmd("bgsave") c.process(cmd) return cmd } -func (c cmdable) ClientKill(ipPort string) *StatusCmd { +func (c *cmdable) ClientKill(ipPort string) *StatusCmd { cmd := NewStatusCmd("client", "kill", ipPort) c.process(cmd) return cmd } -func (c cmdable) ClientList() *StringCmd { +func (c *cmdable) ClientList() *StringCmd { cmd := NewStringCmd("client", "list") c.process(cmd) return cmd } -func (c cmdable) ClientPause(dur time.Duration) *BoolCmd { +func (c *cmdable) ClientPause(dur time.Duration) *BoolCmd { cmd := NewBoolCmd("client", "pause", formatMs(dur)) c.process(cmd) return cmd } // ClientSetName assigns a name to the one of many connections in the pool. -func (c cmdable) ClientSetName(name string) *BoolCmd { +func (c *cmdable) ClientSetName(name string) *BoolCmd { cmd := NewBoolCmd("client", "setname", name) c.process(cmd) return cmd @@ -1441,43 +1441,43 @@ func (c *Client) ClientGetName() *StringCmd { return cmd } -func (c cmdable) ConfigGet(parameter string) *SliceCmd { +func (c *cmdable) ConfigGet(parameter string) *SliceCmd { cmd := NewSliceCmd("config", "get", parameter) c.process(cmd) return cmd } -func (c cmdable) ConfigResetStat() *StatusCmd { +func (c *cmdable) ConfigResetStat() *StatusCmd { cmd := NewStatusCmd("config", "resetstat") c.process(cmd) return cmd } -func (c cmdable) ConfigSet(parameter, value string) *StatusCmd { +func (c *cmdable) ConfigSet(parameter, value string) *StatusCmd { cmd := NewStatusCmd("config", "set", parameter, value) c.process(cmd) return cmd } -func (c cmdable) DbSize() *IntCmd { +func (c *cmdable) DbSize() *IntCmd { cmd := NewIntCmd("dbsize") c.process(cmd) return cmd } -func (c cmdable) FlushAll() *StatusCmd { +func (c *cmdable) FlushAll() *StatusCmd { cmd := NewStatusCmd("flushall") c.process(cmd) return cmd } -func (c cmdable) FlushDb() *StatusCmd { +func (c *cmdable) FlushDb() *StatusCmd { cmd := NewStatusCmd("flushdb") c.process(cmd) return cmd } -func (c cmdable) Info(section ...string) *StringCmd { +func (c *cmdable) Info(section ...string) *StringCmd { args := []interface{}{"info"} if len(section) > 0 { args = append(args, section[0]) @@ -1487,19 +1487,19 @@ func (c cmdable) Info(section ...string) *StringCmd { return cmd } -func (c cmdable) LastSave() *IntCmd { +func (c *cmdable) LastSave() *IntCmd { cmd := NewIntCmd("lastsave") c.process(cmd) return cmd } -func (c cmdable) Save() *StatusCmd { +func (c *cmdable) Save() *StatusCmd { cmd := NewStatusCmd("save") c.process(cmd) return cmd } -func (c cmdable) shutdown(modifier string) *StatusCmd { +func (c *cmdable) shutdown(modifier string) *StatusCmd { var args []interface{} if modifier == "" { args = []interface{}{"shutdown"} @@ -1521,33 +1521,33 @@ func (c cmdable) shutdown(modifier string) *StatusCmd { return cmd } -func (c cmdable) Shutdown() *StatusCmd { +func (c *cmdable) Shutdown() *StatusCmd { return c.shutdown("") } -func (c cmdable) ShutdownSave() *StatusCmd { +func (c *cmdable) ShutdownSave() *StatusCmd { return c.shutdown("save") } -func (c cmdable) ShutdownNoSave() *StatusCmd { +func (c *cmdable) ShutdownNoSave() *StatusCmd { return c.shutdown("nosave") } -func (c cmdable) SlaveOf(host, port string) *StatusCmd { +func (c *cmdable) SlaveOf(host, port string) *StatusCmd { cmd := NewStatusCmd("slaveof", host, port) c.process(cmd) return cmd } -func (c cmdable) SlowLog() { +func (c *cmdable) SlowLog() { panic("not implemented") } -func (c cmdable) Sync() { +func (c *cmdable) Sync() { panic("not implemented") } -func (c cmdable) Time() *StringSliceCmd { +func (c *cmdable) Time() *StringSliceCmd { cmd := NewStringSliceCmd("time") c.process(cmd) return cmd @@ -1555,7 +1555,7 @@ func (c cmdable) Time() *StringSliceCmd { //------------------------------------------------------------------------------ -func (c cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd { +func (c *cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd { cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "eval" cmdArgs[1] = script @@ -1572,7 +1572,7 @@ func (c cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd { return cmd } -func (c cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd { +func (c *cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd { cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "evalsha" cmdArgs[1] = sha1 @@ -1589,7 +1589,7 @@ func (c cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd { return cmd } -func (c cmdable) ScriptExists(scripts ...string) *BoolSliceCmd { +func (c *cmdable) ScriptExists(scripts ...string) *BoolSliceCmd { args := make([]interface{}, 2+len(scripts)) args[0] = "script" args[1] = "exists" @@ -1601,19 +1601,19 @@ func (c cmdable) ScriptExists(scripts ...string) *BoolSliceCmd { return cmd } -func (c cmdable) ScriptFlush() *StatusCmd { +func (c *cmdable) ScriptFlush() *StatusCmd { cmd := NewStatusCmd("script", "flush") c.process(cmd) return cmd } -func (c cmdable) ScriptKill() *StatusCmd { +func (c *cmdable) ScriptKill() *StatusCmd { cmd := NewStatusCmd("script", "kill") c.process(cmd) return cmd } -func (c cmdable) ScriptLoad(script string) *StringCmd { +func (c *cmdable) ScriptLoad(script string) *StringCmd { cmd := NewStringCmd("script", "load", script) c.process(cmd) return cmd @@ -1621,7 +1621,7 @@ func (c cmdable) ScriptLoad(script string) *StringCmd { //------------------------------------------------------------------------------ -func (c cmdable) DebugObject(key string) *StringCmd { +func (c *cmdable) DebugObject(key string) *StringCmd { cmd := NewStringCmd("debug", "object", key) c.process(cmd) return cmd @@ -1629,7 +1629,7 @@ func (c cmdable) DebugObject(key string) *StringCmd { //------------------------------------------------------------------------------ -func (c cmdable) PubSubChannels(pattern string) *StringSliceCmd { +func (c *cmdable) PubSubChannels(pattern string) *StringSliceCmd { args := []interface{}{"pubsub", "channels"} if pattern != "*" { args = append(args, pattern) @@ -1639,7 +1639,7 @@ func (c cmdable) PubSubChannels(pattern string) *StringSliceCmd { return cmd } -func (c cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd { +func (c *cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd { args := make([]interface{}, 2+len(channels)) args[0] = "pubsub" args[1] = "numsub" @@ -1651,7 +1651,7 @@ func (c cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd { return cmd } -func (c cmdable) PubSubNumPat() *IntCmd { +func (c *cmdable) PubSubNumPat() *IntCmd { cmd := NewIntCmd("pubsub", "numpat") c.process(cmd) return cmd @@ -1659,73 +1659,73 @@ func (c cmdable) PubSubNumPat() *IntCmd { //------------------------------------------------------------------------------ -func (c cmdable) ClusterSlots() *ClusterSlotsCmd { +func (c *cmdable) ClusterSlots() *ClusterSlotsCmd { cmd := NewClusterSlotsCmd("cluster", "slots") c.process(cmd) return cmd } -func (c cmdable) ClusterNodes() *StringCmd { +func (c *cmdable) ClusterNodes() *StringCmd { cmd := NewStringCmd("cluster", "nodes") c.process(cmd) return cmd } -func (c cmdable) ClusterMeet(host, port string) *StatusCmd { +func (c *cmdable) ClusterMeet(host, port string) *StatusCmd { cmd := NewStatusCmd("cluster", "meet", host, port) c.process(cmd) return cmd } -func (c cmdable) ClusterForget(nodeID string) *StatusCmd { +func (c *cmdable) ClusterForget(nodeID string) *StatusCmd { cmd := NewStatusCmd("cluster", "forget", nodeID) c.process(cmd) return cmd } -func (c cmdable) ClusterReplicate(nodeID string) *StatusCmd { +func (c *cmdable) ClusterReplicate(nodeID string) *StatusCmd { cmd := NewStatusCmd("cluster", "replicate", nodeID) c.process(cmd) return cmd } -func (c cmdable) ClusterResetSoft() *StatusCmd { +func (c *cmdable) ClusterResetSoft() *StatusCmd { cmd := NewStatusCmd("cluster", "reset", "soft") c.process(cmd) return cmd } -func (c cmdable) ClusterResetHard() *StatusCmd { +func (c *cmdable) ClusterResetHard() *StatusCmd { cmd := NewStatusCmd("cluster", "reset", "hard") c.process(cmd) return cmd } -func (c cmdable) ClusterInfo() *StringCmd { +func (c *cmdable) ClusterInfo() *StringCmd { cmd := NewStringCmd("cluster", "info") c.process(cmd) return cmd } -func (c cmdable) ClusterKeySlot(key string) *IntCmd { +func (c *cmdable) ClusterKeySlot(key string) *IntCmd { cmd := NewIntCmd("cluster", "keyslot", key) c.process(cmd) return cmd } -func (c cmdable) ClusterCountFailureReports(nodeID string) *IntCmd { +func (c *cmdable) ClusterCountFailureReports(nodeID string) *IntCmd { cmd := NewIntCmd("cluster", "count-failure-reports", nodeID) c.process(cmd) return cmd } -func (c cmdable) ClusterCountKeysInSlot(slot int) *IntCmd { +func (c *cmdable) ClusterCountKeysInSlot(slot int) *IntCmd { cmd := NewIntCmd("cluster", "countkeysinslot", slot) c.process(cmd) return cmd } -func (c cmdable) ClusterDelSlots(slots ...int) *StatusCmd { +func (c *cmdable) ClusterDelSlots(slots ...int) *StatusCmd { args := make([]interface{}, 2+len(slots)) args[0] = "cluster" args[1] = "delslots" @@ -1737,7 +1737,7 @@ func (c cmdable) ClusterDelSlots(slots ...int) *StatusCmd { return cmd } -func (c cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd { +func (c *cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd { size := max - min + 1 slots := make([]int, size) for i := 0; i < size; i++ { @@ -1746,37 +1746,37 @@ func (c cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd { return c.ClusterDelSlots(slots...) } -func (c cmdable) ClusterSaveConfig() *StatusCmd { +func (c *cmdable) ClusterSaveConfig() *StatusCmd { cmd := NewStatusCmd("cluster", "saveconfig") c.process(cmd) return cmd } -func (c cmdable) ClusterSlaves(nodeID string) *StringSliceCmd { +func (c *cmdable) ClusterSlaves(nodeID string) *StringSliceCmd { cmd := NewStringSliceCmd("cluster", "slaves", nodeID) c.process(cmd) return cmd } -func (c statefulCmdable) ReadOnly() *StatusCmd { +func (c *statefulCmdable) ReadOnly() *StatusCmd { cmd := NewStatusCmd("readonly") c.process(cmd) return cmd } -func (c statefulCmdable) ReadWrite() *StatusCmd { +func (c *statefulCmdable) ReadWrite() *StatusCmd { cmd := NewStatusCmd("readwrite") c.process(cmd) return cmd } -func (c cmdable) ClusterFailover() *StatusCmd { +func (c *cmdable) ClusterFailover() *StatusCmd { cmd := NewStatusCmd("cluster", "failover") c.process(cmd) return cmd } -func (c cmdable) ClusterAddSlots(slots ...int) *StatusCmd { +func (c *cmdable) ClusterAddSlots(slots ...int) *StatusCmd { args := make([]interface{}, 2+len(slots)) args[0] = "cluster" args[1] = "addslots" @@ -1788,7 +1788,7 @@ func (c cmdable) ClusterAddSlots(slots ...int) *StatusCmd { return cmd } -func (c cmdable) ClusterAddSlotsRange(min, max int) *StatusCmd { +func (c *cmdable) ClusterAddSlotsRange(min, max int) *StatusCmd { size := max - min + 1 slots := make([]int, size) for i := 0; i < size; i++ { @@ -1799,7 +1799,7 @@ func (c cmdable) ClusterAddSlotsRange(min, max int) *StatusCmd { //------------------------------------------------------------------------------ -func (c cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd { +func (c *cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd { args := make([]interface{}, 2+3*len(geoLocation)) args[0] = "geoadd" args[1] = key @@ -1813,19 +1813,19 @@ func (c cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd { return cmd } -func (c cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd { +func (c *cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd { cmd := NewGeoLocationCmd(query, "georadius", key, longitude, latitude) c.process(cmd) return cmd } -func (c cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd { +func (c *cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd { cmd := NewGeoLocationCmd(query, "georadiusbymember", key, member) c.process(cmd) return cmd } -func (c cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd { +func (c *cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd { if unit == "" { unit = "km" } @@ -1834,7 +1834,7 @@ func (c cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd { return cmd } -func (c cmdable) GeoHash(key string, members ...string) *StringSliceCmd { +func (c *cmdable) GeoHash(key string, members ...string) *StringSliceCmd { args := make([]interface{}, 2+len(members)) args[0] = "geohash" args[1] = key @@ -1848,7 +1848,7 @@ func (c cmdable) GeoHash(key string, members ...string) *StringSliceCmd { //------------------------------------------------------------------------------ -func (c cmdable) Command() *CommandsInfoCmd { +func (c *cmdable) Command() *CommandsInfoCmd { cmd := NewCommandsInfoCmd("command") c.process(cmd) return cmd diff --git a/iterator.go b/iterator.go index 0219ab4..e9dfbad 100644 --- a/iterator.go +++ b/iterator.go @@ -3,7 +3,7 @@ package redis import "sync" type Scanner struct { - client cmdable + client *cmdable *ScanCmd } diff --git a/pipeline.go b/pipeline.go index e946b9e..fed6e0c 100644 --- a/pipeline.go +++ b/pipeline.go @@ -22,32 +22,32 @@ type Pipeline struct { closed int32 } -func (pipe *Pipeline) Process(cmd Cmder) error { - pipe.mu.Lock() - pipe.cmds = append(pipe.cmds, cmd) - pipe.mu.Unlock() +func (c *Pipeline) Process(cmd Cmder) error { + c.mu.Lock() + c.cmds = append(c.cmds, cmd) + c.mu.Unlock() return nil } // Close closes the pipeline, releasing any open resources. -func (pipe *Pipeline) Close() error { - atomic.StoreInt32(&pipe.closed, 1) - pipe.Discard() +func (c *Pipeline) Close() error { + atomic.StoreInt32(&c.closed, 1) + c.Discard() return nil } -func (pipe *Pipeline) isClosed() bool { - return atomic.LoadInt32(&pipe.closed) == 1 +func (c *Pipeline) isClosed() bool { + return atomic.LoadInt32(&c.closed) == 1 } // Discard resets the pipeline and discards queued commands. -func (pipe *Pipeline) Discard() error { - defer pipe.mu.Unlock() - pipe.mu.Lock() - if pipe.isClosed() { +func (c *Pipeline) Discard() error { + defer c.mu.Unlock() + c.mu.Lock() + if c.isClosed() { return pool.ErrClosed } - pipe.cmds = pipe.cmds[:0] + c.cmds = c.cmds[:0] return nil } @@ -56,30 +56,30 @@ func (pipe *Pipeline) Discard() error { // // Exec always returns list of commands and error of the first failed // command if any. -func (pipe *Pipeline) Exec() ([]Cmder, error) { - if pipe.isClosed() { +func (c *Pipeline) Exec() ([]Cmder, error) { + if c.isClosed() { return nil, pool.ErrClosed } - defer pipe.mu.Unlock() - pipe.mu.Lock() + defer c.mu.Unlock() + c.mu.Lock() - if len(pipe.cmds) == 0 { - return pipe.cmds, nil + if len(c.cmds) == 0 { + return c.cmds, nil } - cmds := pipe.cmds - pipe.cmds = nil + cmds := c.cmds + c.cmds = nil - return cmds, pipe.exec(cmds) + return cmds, c.exec(cmds) } -func (pipe *Pipeline) pipelined(fn func(*Pipeline) error) ([]Cmder, error) { - if err := fn(pipe); err != nil { +func (c *Pipeline) pipelined(fn func(*Pipeline) error) ([]Cmder, error) { + if err := fn(c); err != nil { return nil, err } - cmds, err := pipe.Exec() - _ = pipe.Close() + cmds, err := c.Exec() + _ = c.Close() return cmds, err } diff --git a/ring.go b/ring.go index 50476fa..8aba07e 100644 --- a/ring.go +++ b/ring.go @@ -102,7 +102,7 @@ func (shard *ringShard) Vote(up bool) bool { // concurrent use by multiple goroutines. // // Ring monitors the state of each shard and removes dead shards from -// the ring. When shard comes online it is added back to the ring. This +// the c. When shard comes online it is added back to the c. This // gives you maximum availability and partition tolerance, but no // consistency between different shards or even clients. Each client // uses shards that are available to the client and does not do any @@ -149,58 +149,58 @@ func NewRing(opt *RingOptions) *Ring { return ring } -func (ring *Ring) cmdInfo(name string) *CommandInfo { - ring.cmdsInfoOnce.Do(func() { - for _, shard := range ring.shards { +func (c *Ring) cmdInfo(name string) *CommandInfo { + c.cmdsInfoOnce.Do(func() { + for _, shard := range c.shards { cmdsInfo, err := shard.Client.Command().Result() if err == nil { - ring.cmdsInfo = cmdsInfo + c.cmdsInfo = cmdsInfo return } } - ring.cmdsInfoOnce = &sync.Once{} + c.cmdsInfoOnce = &sync.Once{} }) - if ring.cmdsInfo == nil { + if c.cmdsInfo == nil { return nil } - return ring.cmdsInfo[name] + return c.cmdsInfo[name] } -func (ring *Ring) cmdFirstKey(cmd Cmder) string { - cmdInfo := ring.cmdInfo(cmd.arg(0)) +func (c *Ring) cmdFirstKey(cmd Cmder) string { + cmdInfo := c.cmdInfo(cmd.arg(0)) if cmdInfo == nil { return "" } return cmd.arg(int(cmdInfo.FirstKeyPos)) } -func (ring *Ring) addClient(name string, cl *Client) { - ring.mu.Lock() - ring.hash.Add(name) - ring.shards[name] = &ringShard{Client: cl} - ring.mu.Unlock() +func (c *Ring) addClient(name string, cl *Client) { + c.mu.Lock() + c.hash.Add(name) + c.shards[name] = &ringShard{Client: cl} + c.mu.Unlock() } -func (ring *Ring) getClient(key string) (*Client, error) { - ring.mu.RLock() +func (c *Ring) getClient(key string) (*Client, error) { + c.mu.RLock() - if ring.closed { + if c.closed { return nil, pool.ErrClosed } - name := ring.hash.Get(hashtag.Key(key)) + name := c.hash.Get(hashtag.Key(key)) if name == "" { - ring.mu.RUnlock() + c.mu.RUnlock() return nil, errRingShardsDown } - cl := ring.shards[name].Client - ring.mu.RUnlock() + cl := c.shards[name].Client + c.mu.RUnlock() return cl, nil } -func (ring *Ring) Process(cmd Cmder) error { - cl, err := ring.getClient(ring.cmdFirstKey(cmd)) +func (c *Ring) Process(cmd Cmder) error { + cl, err := c.getClient(c.cmdFirstKey(cmd)) if err != nil { cmd.setErr(err) return err @@ -208,34 +208,34 @@ func (ring *Ring) Process(cmd Cmder) error { return cl.baseClient.Process(cmd) } -// rebalance removes dead shards from the ring. -func (ring *Ring) rebalance() { - defer ring.mu.Unlock() - ring.mu.Lock() +// rebalance removes dead shards from the c. +func (c *Ring) rebalance() { + defer c.mu.Unlock() + c.mu.Lock() - ring.hash = consistenthash.New(ring.nreplicas, nil) - for name, shard := range ring.shards { + c.hash = consistenthash.New(c.nreplicas, nil) + for name, shard := range c.shards { if shard.IsUp() { - ring.hash.Add(name) + c.hash.Add(name) } } } -// heartbeat monitors state of each shard in the ring. -func (ring *Ring) heartbeat() { +// heartbeat monitors state of each shard in the c. +func (c *Ring) heartbeat() { ticker := time.NewTicker(100 * time.Millisecond) defer ticker.Stop() for _ = range ticker.C { var rebalance bool - ring.mu.RLock() + c.mu.RLock() - if ring.closed { - ring.mu.RUnlock() + if c.closed { + c.mu.RUnlock() break } - for _, shard := range ring.shards { + for _, shard := range c.shards { err := shard.Client.Ping().Err() if shard.Vote(err == nil || err == pool.ErrPoolTimeout) { internal.Logf("ring shard state changed: %s", shard) @@ -243,10 +243,10 @@ func (ring *Ring) heartbeat() { } } - ring.mu.RUnlock() + c.mu.RUnlock() if rebalance { - ring.rebalance() + c.rebalance() } } } @@ -255,45 +255,45 @@ func (ring *Ring) heartbeat() { // // It is rare to Close a Ring, as the Ring is meant to be long-lived // and shared between many goroutines. -func (ring *Ring) Close() (retErr error) { - defer ring.mu.Unlock() - ring.mu.Lock() +func (c *Ring) Close() (retErr error) { + defer c.mu.Unlock() + c.mu.Lock() - if ring.closed { + if c.closed { return nil } - ring.closed = true + c.closed = true - for _, shard := range ring.shards { + for _, shard := range c.shards { if err := shard.Client.Close(); err != nil { retErr = err } } - ring.hash = nil - ring.shards = nil + c.hash = nil + c.shards = nil return retErr } -func (ring *Ring) Pipeline() *Pipeline { +func (c *Ring) Pipeline() *Pipeline { pipe := Pipeline{ - exec: ring.pipelineExec, + exec: c.pipelineExec, } pipe.cmdable.process = pipe.Process pipe.statefulCmdable.process = pipe.Process return &pipe } -func (ring *Ring) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) { - return ring.Pipeline().pipelined(fn) +func (c *Ring) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) { + return c.Pipeline().pipelined(fn) } -func (ring *Ring) pipelineExec(cmds []Cmder) error { +func (c *Ring) pipelineExec(cmds []Cmder) error { var retErr error cmdsMap := make(map[string][]Cmder) for _, cmd := range cmds { - name := ring.hash.Get(hashtag.Key(ring.cmdFirstKey(cmd))) + name := c.hash.Get(hashtag.Key(c.cmdFirstKey(cmd))) if name == "" { cmd.setErr(errRingShardsDown) if retErr == nil { @@ -304,11 +304,11 @@ func (ring *Ring) pipelineExec(cmds []Cmder) error { cmdsMap[name] = append(cmdsMap[name], cmd) } - for i := 0; i <= ring.opt.MaxRetries; i++ { + for i := 0; i <= c.opt.MaxRetries; i++ { failedCmdsMap := make(map[string][]Cmder) for name, cmds := range cmdsMap { - client := ring.shards[name].Client + client := c.shards[name].Client cn, err := client.conn() if err != nil { setCmdsErr(cmds, err) diff --git a/tx.go b/tx.go index 4f85cc8..5ed223c 100644 --- a/tx.go +++ b/tx.go @@ -39,7 +39,7 @@ func (c *Client) Watch(fn func(*Tx) error, keys ...string) error { tx := c.newTx() if len(keys) > 0 { if err := tx.Watch(keys...).Err(); err != nil { - tx.close() + _ = tx.close() return err } } @@ -50,57 +50,57 @@ func (c *Client) Watch(fn func(*Tx) error, keys ...string) error { return retErr } -func (tx *Tx) Process(cmd Cmder) error { - if tx.cmds == nil { - return tx.baseClient.Process(cmd) +func (c *Tx) Process(cmd Cmder) error { + if c.cmds == nil { + return c.baseClient.Process(cmd) } - tx.cmds = append(tx.cmds, cmd) + c.cmds = append(c.cmds, cmd) return nil } // close closes the transaction, releasing any open resources. -func (tx *Tx) close() error { - if tx.closed { +func (c *Tx) close() error { + if c.closed { return nil } - tx.closed = true - if err := tx.Unwatch().Err(); err != nil { + c.closed = true + if err := c.Unwatch().Err(); err != nil { internal.Logf("Unwatch failed: %s", err) } - return tx.baseClient.Close() + return c.baseClient.Close() } // Watch marks the keys to be watched for conditional execution // of a transaction. -func (tx *Tx) Watch(keys ...string) *StatusCmd { +func (c *Tx) Watch(keys ...string) *StatusCmd { args := make([]interface{}, 1+len(keys)) args[0] = "WATCH" for i, key := range keys { args[1+i] = key } cmd := NewStatusCmd(args...) - tx.Process(cmd) + c.Process(cmd) return cmd } // Unwatch flushes all the previously watched keys for a transaction. -func (tx *Tx) Unwatch(keys ...string) *StatusCmd { +func (c *Tx) Unwatch(keys ...string) *StatusCmd { args := make([]interface{}, 1+len(keys)) args[0] = "UNWATCH" for i, key := range keys { args[1+i] = key } cmd := NewStatusCmd(args...) - tx.Process(cmd) + c.Process(cmd) return cmd } // Discard discards queued commands. -func (tx *Tx) Discard() error { - if tx.cmds == nil { +func (c *Tx) Discard() error { + if c.cmds == nil { return errDiscard } - tx.cmds = tx.cmds[:1] + c.cmds = c.cmds[:1] return nil } @@ -113,19 +113,19 @@ func (tx *Tx) Discard() error { // Exec always returns list of commands. If transaction fails // TxFailedErr is returned. Otherwise Exec returns error of the first // failed command or nil. -func (tx *Tx) MultiExec(fn func() error) ([]Cmder, error) { - if tx.closed { +func (c *Tx) MultiExec(fn func() error) ([]Cmder, error) { + if c.closed { return nil, pool.ErrClosed } - tx.cmds = []Cmder{NewStatusCmd("MULTI")} + c.cmds = []Cmder{NewStatusCmd("MULTI")} if err := fn(); err != nil { return nil, err } - tx.cmds = append(tx.cmds, NewSliceCmd("EXEC")) + c.cmds = append(c.cmds, NewSliceCmd("EXEC")) - cmds := tx.cmds - tx.cmds = nil + cmds := c.cmds + c.cmds = nil if len(cmds) == 2 { return []Cmder{}, nil @@ -134,18 +134,18 @@ func (tx *Tx) MultiExec(fn func() error) ([]Cmder, error) { // Strip MULTI and EXEC commands. retCmds := cmds[1 : len(cmds)-1] - cn, err := tx.conn() + cn, err := c.conn() if err != nil { setCmdsErr(retCmds, err) return retCmds, err } - err = tx.execCmds(cn, cmds) - tx.putConn(cn, err, false) + err = c.execCmds(cn, cmds) + c.putConn(cn, err, false) return retCmds, err } -func (tx *Tx) execCmds(cn *pool.Conn, cmds []Cmder) error { +func (c *Tx) execCmds(cn *pool.Conn, cmds []Cmder) error { err := writeCmd(cn, cmds...) if err != nil { setCmdsErr(cmds[1:len(cmds)-1], err)