diff --git a/cluster.go b/cluster.go index cd433e7..e29d6ef 100644 --- a/cluster.go +++ b/cluster.go @@ -21,7 +21,7 @@ type clusterNode struct { // or more underlying connections. It's safe for concurrent use by // multiple goroutines. type ClusterClient struct { - commandable + cmdable opt *ClusterOptions @@ -51,7 +51,7 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { cmdsInfoOnce: new(sync.Once), } - client.commandable.process = client.process + client.cmdable.process = client.Process for _, addr := range opt.Addrs { _ = client.nodeByAddr(addr) @@ -242,7 +242,7 @@ func (c *ClusterClient) cmdSlotAndNode(cmd Cmder) (int, *clusterNode) { return slot, c.slotMasterNode(slot) } -func (c *ClusterClient) process(cmd Cmder) { +func (c *ClusterClient) Process(cmd Cmder) { var ask bool slot, node := c.cmdSlotAndNode(cmd) @@ -398,11 +398,12 @@ func (c *ClusterClient) reaper(frequency time.Duration) { } func (c *ClusterClient) Pipeline() *Pipeline { - pipe := &Pipeline{ + pipe := Pipeline{ exec: c.pipelineExec, } - pipe.commandable.process = pipe.process - return pipe + pipe.cmdable.process = pipe.Process + pipe.statefulCmdable.process = pipe.Process + return &pipe } func (c *ClusterClient) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) { diff --git a/cluster_test.go b/cluster_test.go index 6d081df..9cdbc00 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -300,17 +300,17 @@ var _ = Describe("Cluster", func() { Expect(nodesList).Should(HaveLen(1)) }) - It("should CLUSTER READONLY", func() { - res, err := cluster.primary().ReadOnly().Result() - Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal("OK")) - }) + // It("should CLUSTER READONLY", func() { + // res, err := cluster.primary().ReadOnly().Result() + // Expect(err).NotTo(HaveOccurred()) + // Expect(res).To(Equal("OK")) + // }) - It("should CLUSTER READWRITE", func() { - res, err := cluster.primary().ReadWrite().Result() - Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal("OK")) - }) + // It("should CLUSTER READWRITE", func() { + // res, err := cluster.primary().ReadWrite().Result() + // Expect(err).NotTo(HaveOccurred()) + // Expect(res).To(Equal("OK")) + // }) }) Describe("Client", func() { diff --git a/commands.go b/commands.go index 00b047f..5107b7b 100644 --- a/commands.go +++ b/commands.go @@ -51,88 +51,88 @@ func formatSec(dur time.Duration) string { return formatInt(int64(dur / time.Second)) } -type commandable struct { +type cmdable struct { process func(cmd Cmder) } -func (c *commandable) Process(cmd Cmder) { - c.process(cmd) +type statefulCmdable struct { + process func(cmd Cmder) } //------------------------------------------------------------------------------ -func (c *commandable) Auth(password string) *StatusCmd { +func (c statefulCmdable) Auth(password string) *StatusCmd { cmd := NewStatusCmd("auth", password) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Echo(message string) *StringCmd { +func (c *cmdable) Echo(message string) *StringCmd { cmd := NewStringCmd("echo", message) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Ping() *StatusCmd { +func (c *cmdable) Ping() *StatusCmd { cmd := NewStatusCmd("ping") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Quit() *StatusCmd { +func (c cmdable) Quit() *StatusCmd { panic("not implemented") } -func (c *commandable) Select(index int64) *StatusCmd { +func (c statefulCmdable) Select(index int) *StatusCmd { cmd := NewStatusCmd("select", index) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) 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 { args[1+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Dump(key string) *StringCmd { +func (c cmdable) Dump(key string) *StringCmd { cmd := NewStringCmd("dump", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Exists(key string) *BoolCmd { +func (c cmdable) Exists(key string) *BoolCmd { cmd := NewBoolCmd("exists", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) Keys(pattern string) *StringSliceCmd { +func (c cmdable) Keys(pattern string) *StringSliceCmd { cmd := NewStringSliceCmd("keys", pattern) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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, @@ -142,17 +142,17 @@ func (c *commandable) Migrate(host, port, key string, db int64, timeout time.Dur formatMs(timeout), ) cmd.setReadTimeout(readTimeout(timeout)) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Move(key string, db int64) *BoolCmd { +func (c cmdable) Move(key string, db int64) *BoolCmd { cmd := NewBoolCmd("move", key, db) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ObjectRefCount(keys ...string) *IntCmd { +func (c cmdable) ObjectRefCount(keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "refcount" @@ -160,11 +160,11 @@ func (c *commandable) ObjectRefCount(keys ...string) *IntCmd { args[2+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ObjectEncoding(keys ...string) *StringCmd { +func (c cmdable) ObjectEncoding(keys ...string) *StringCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "encoding" @@ -172,11 +172,11 @@ func (c *commandable) ObjectEncoding(keys ...string) *StringCmd { args[2+i] = key } cmd := NewStringCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ObjectIdleTime(keys ...string) *DurationCmd { +func (c cmdable) ObjectIdleTime(keys ...string) *DurationCmd { args := make([]interface{}, 2+len(keys)) args[0] = "object" args[1] = "idletime" @@ -184,68 +184,68 @@ func (c *commandable) ObjectIdleTime(keys ...string) *DurationCmd { args[2+i] = key } cmd := NewDurationCmd(time.Second, args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Persist(key string) *BoolCmd { +func (c cmdable) Persist(key string) *BoolCmd { cmd := NewBoolCmd("persist", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) PExpireAt(key string, tm time.Time) *BoolCmd { +func (c cmdable) PExpireAt(key string, tm time.Time) *BoolCmd { cmd := NewBoolCmd( "pexpireat", key, tm.UnixNano()/int64(time.Millisecond), ) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) PTTL(key string) *DurationCmd { +func (c cmdable) PTTL(key string) *DurationCmd { cmd := NewDurationCmd(time.Millisecond, "pttl", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RandomKey() *StringCmd { +func (c cmdable) RandomKey() *StringCmd { cmd := NewStringCmd("randomkey") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Rename(key, newkey string) *StatusCmd { +func (c cmdable) Rename(key, newkey string) *StatusCmd { cmd := NewStatusCmd("rename", key, newkey) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RenameNX(key, newkey string) *BoolCmd { +func (c cmdable) RenameNX(key, newkey string) *BoolCmd { cmd := NewBoolCmd("renamenx", key, newkey) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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, formatMs(ttl), value, ) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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, @@ -253,7 +253,7 @@ func (c *commandable) RestoreReplace(key string, ttl time.Duration, value string value, "replace", ) - c.Process(cmd) + c.process(cmd) return cmd } @@ -289,31 +289,31 @@ func (sort *Sort) args(key string) []interface{} { return args } -func (c *commandable) Sort(key string, sort Sort) *StringSliceCmd { +func (c cmdable) Sort(key string, sort Sort) *StringSliceCmd { cmd := NewStringSliceCmd(sort.args(key)...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SortInterfaces(key string, sort Sort) *SliceCmd { +func (c cmdable) SortInterfaces(key string, sort Sort) *SliceCmd { cmd := NewSliceCmd(sort.args(key)...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) TTL(key string) *DurationCmd { +func (c cmdable) TTL(key string) *DurationCmd { cmd := NewDurationCmd(time.Second, "ttl", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Type(key string) *StatusCmd { +func (c cmdable) Type(key string) *StatusCmd { cmd := NewStatusCmd("type", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) @@ -322,14 +322,14 @@ func (c *commandable) Scan(cursor uint64, match string, count int64) Scanner { args = append(args, "count", count) } cmd := NewScanCmd(args...) - c.Process(cmd) + c.process(cmd) return Scanner{ client: c, ScanCmd: cmd, } } -func (c *commandable) 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) @@ -338,14 +338,14 @@ func (c *commandable) SScan(key string, cursor uint64, match string, count int64 args = append(args, "count", count) } cmd := NewScanCmd(args...) - c.Process(cmd) + c.process(cmd) return Scanner{ client: c, ScanCmd: cmd, } } -func (c *commandable) 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) @@ -354,14 +354,14 @@ func (c *commandable) HScan(key string, cursor uint64, match string, count int64 args = append(args, "count", count) } cmd := NewScanCmd(args...) - c.Process(cmd) + c.process(cmd) return Scanner{ client: c, ScanCmd: cmd, } } -func (c *commandable) 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) @@ -370,7 +370,7 @@ func (c *commandable) ZScan(key string, cursor uint64, match string, count int64 args = append(args, "count", count) } cmd := NewScanCmd(args...) - c.Process(cmd) + c.process(cmd) return Scanner{ client: c, ScanCmd: cmd, @@ -379,9 +379,9 @@ func (c *commandable) ZScan(key string, cursor uint64, match string, count int64 //------------------------------------------------------------------------------ -func (c *commandable) Append(key, value string) *IntCmd { +func (c cmdable) Append(key, value string) *IntCmd { cmd := NewIntCmd("append", key, value) - c.Process(cmd) + c.process(cmd) return cmd } @@ -389,7 +389,7 @@ type BitCount struct { Start, End int64 } -func (c *commandable) BitCount(key string, bitCount *BitCount) *IntCmd { +func (c cmdable) BitCount(key string, bitCount *BitCount) *IntCmd { args := []interface{}{"bitcount", key} if bitCount != nil { args = append( @@ -399,11 +399,11 @@ func (c *commandable) BitCount(key string, bitCount *BitCount) *IntCmd { ) } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -412,27 +412,27 @@ func (c *commandable) bitOp(op, destKey string, keys ...string) *IntCmd { args[3+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) BitOpAnd(destKey string, keys ...string) *IntCmd { +func (c cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd { return c.bitOp("and", destKey, keys...) } -func (c *commandable) BitOpOr(destKey string, keys ...string) *IntCmd { +func (c cmdable) BitOpOr(destKey string, keys ...string) *IntCmd { return c.bitOp("or", destKey, keys...) } -func (c *commandable) BitOpXor(destKey string, keys ...string) *IntCmd { +func (c cmdable) BitOpXor(destKey string, keys ...string) *IntCmd { return c.bitOp("xor", destKey, keys...) } -func (c *commandable) BitOpNot(destKey string, key string) *IntCmd { +func (c cmdable) BitOpNot(destKey string, key string) *IntCmd { return c.bitOp("not", destKey, key) } -func (c *commandable) 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 @@ -448,101 +448,101 @@ func (c *commandable) BitPos(key string, bit int64, pos ...int64) *IntCmd { panic("too many arguments") } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Decr(key string) *IntCmd { +func (c cmdable) Decr(key string) *IntCmd { cmd := NewIntCmd("decr", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) DecrBy(key string, decrement int64) *IntCmd { +func (c cmdable) DecrBy(key string, decrement int64) *IntCmd { cmd := NewIntCmd("decrby", key, decrement) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Get(key string) *StringCmd { +func (c cmdable) Get(key string) *StringCmd { cmd := NewStringCmd("get", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) GetBit(key string, offset int64) *IntCmd { +func (c cmdable) GetBit(key string, offset int64) *IntCmd { cmd := NewIntCmd("getbit", key, offset) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) GetSet(key string, value interface{}) *StringCmd { +func (c cmdable) GetSet(key string, value interface{}) *StringCmd { cmd := NewStringCmd("getset", key, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Incr(key string) *IntCmd { +func (c cmdable) Incr(key string) *IntCmd { cmd := NewIntCmd("incr", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) IncrBy(key string, value int64) *IntCmd { +func (c cmdable) IncrBy(key string, value int64) *IntCmd { cmd := NewIntCmd("incrby", key, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) IncrByFloat(key string, value float64) *FloatCmd { +func (c cmdable) IncrByFloat(key string, value float64) *FloatCmd { cmd := NewFloatCmd("incrbyfloat", key, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { args[1+i] = key } cmd := NewSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) MSet(pairs ...string) *StatusCmd { +func (c cmdable) MSet(pairs ...string) *StatusCmd { args := make([]interface{}, 1+len(pairs)) args[0] = "mset" for i, pair := range pairs { args[1+i] = pair } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) MSetNX(pairs ...string) *BoolCmd { +func (c cmdable) MSetNX(pairs ...string) *BoolCmd { args := make([]interface{}, 1+len(pairs)) args[0] = "msetnx" for i, pair := range pairs { args[1+i] = pair } cmd := NewBoolCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `SET key value [expiration]` command. // // Zero expiration means the key has no expiration time. -func (c *commandable) 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 @@ -555,25 +555,25 @@ func (c *commandable) Set(key string, value interface{}, expiration time.Duratio } } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SetBit(key string, offset int64, value int) *IntCmd { +func (c cmdable) SetBit(key string, offset int64, value int) *IntCmd { cmd := NewIntCmd( "SETBIT", key, offset, value, ) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `SET key value [expiration] NX` command. // // Zero expiration means the key has no expiration time. -func (c *commandable) 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. @@ -585,39 +585,39 @@ func (c *commandable) SetNX(key string, value interface{}, expiration time.Durat cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "nx") } } - c.Process(cmd) + c.process(cmd) return cmd } // Redis `SET key value [expiration] XX` command. // // Zero expiration means the key has no expiration time. -func (c *commandable) 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") } else { cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx") } - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) StrLen(key string) *IntCmd { +func (c cmdable) StrLen(key string) *IntCmd { cmd := NewIntCmd("strlen", key) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) 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 @@ -625,53 +625,53 @@ func (c *commandable) HDel(key string, fields ...string) *IntCmd { args[2+i] = field } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HExists(key, field string) *BoolCmd { +func (c cmdable) HExists(key, field string) *BoolCmd { cmd := NewBoolCmd("hexists", key, field) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HGet(key, field string) *StringCmd { +func (c cmdable) HGet(key, field string) *StringCmd { cmd := NewStringCmd("hget", key, field) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HGetAll(key string) *StringStringMapCmd { +func (c cmdable) HGetAll(key string) *StringStringMapCmd { cmd := NewStringStringMapCmd("hgetall", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) HKeys(key string) *StringSliceCmd { +func (c cmdable) HKeys(key string) *StringSliceCmd { cmd := NewStringSliceCmd("hkeys", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HLen(key string) *IntCmd { +func (c cmdable) HLen(key string) *IntCmd { cmd := NewIntCmd("hlen", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -679,11 +679,11 @@ func (c *commandable) HMGet(key string, fields ...string) *SliceCmd { args[2+i] = field } cmd := NewSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -694,31 +694,31 @@ func (c *commandable) HMSet(key string, fields map[string]string) *StatusCmd { i += 2 } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HSet(key, field, value string) *BoolCmd { +func (c cmdable) HSet(key, field, value string) *BoolCmd { cmd := NewBoolCmd("hset", key, field, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HSetNX(key, field, value string) *BoolCmd { +func (c cmdable) HSetNX(key, field, value string) *BoolCmd { cmd := NewBoolCmd("hsetnx", key, field, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) HVals(key string) *StringSliceCmd { +func (c cmdable) HVals(key string) *StringSliceCmd { cmd := NewStringSliceCmd("hvals", key) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) 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 { @@ -727,11 +727,11 @@ func (c *commandable) BLPop(timeout time.Duration, keys ...string) *StringSliceC args[len(args)-1] = formatSec(timeout) cmd := NewStringSliceCmd(args...) cmd.setReadTimeout(readTimeout(timeout)) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { @@ -740,11 +740,11 @@ func (c *commandable) BRPop(timeout time.Duration, keys ...string) *StringSliceC args[len(keys)+1] = formatSec(timeout) cmd := NewStringSliceCmd(args...) cmd.setReadTimeout(readTimeout(timeout)) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd { +func (c cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd { cmd := NewStringCmd( "brpoplpush", source, @@ -752,35 +752,35 @@ func (c *commandable) BRPopLPush(source, destination string, timeout time.Durati formatSec(timeout), ) cmd.setReadTimeout(readTimeout(timeout)) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LIndex(key string, index int64) *StringCmd { +func (c cmdable) LIndex(key string, index int64) *StringCmd { cmd := NewStringCmd("lindex", key, index) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LInsert(key, op, pivot, value string) *IntCmd { +func (c cmdable) LInsert(key, op, pivot, value string) *IntCmd { cmd := NewIntCmd("linsert", key, op, pivot, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LLen(key string) *IntCmd { +func (c cmdable) LLen(key string) *IntCmd { cmd := NewIntCmd("llen", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LPop(key string) *StringCmd { +func (c cmdable) LPop(key string) *StringCmd { cmd := NewStringCmd("lpop", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LPush(key string, values ...string) *IntCmd { +func (c cmdable) LPush(key string, values ...string) *IntCmd { args := make([]interface{}, 2+len(values)) args[0] = "lpush" args[1] = key @@ -788,63 +788,63 @@ func (c *commandable) LPush(key string, values ...string) *IntCmd { args[2+i] = value } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LPushX(key, value interface{}) *IntCmd { +func (c cmdable) LPushX(key, value interface{}) *IntCmd { cmd := NewIntCmd("lpushx", key, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LRange(key string, start, stop int64) *StringSliceCmd { +func (c cmdable) LRange(key string, start, stop int64) *StringSliceCmd { cmd := NewStringSliceCmd( "lrange", key, start, stop, ) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) LTrim(key string, start, stop int64) *StatusCmd { +func (c cmdable) LTrim(key string, start, stop int64) *StatusCmd { cmd := NewStatusCmd( "ltrim", key, start, stop, ) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RPop(key string) *StringCmd { +func (c cmdable) RPop(key string) *StringCmd { cmd := NewStringCmd("rpop", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RPopLPush(source, destination string) *StringCmd { +func (c cmdable) RPopLPush(source, destination string) *StringCmd { cmd := NewStringCmd("rpoplpush", source, destination) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RPush(key string, values ...string) *IntCmd { +func (c cmdable) RPush(key string, values ...string) *IntCmd { args := make([]interface{}, 2+len(values)) args[0] = "rpush" args[1] = key @@ -852,19 +852,19 @@ func (c *commandable) RPush(key string, values ...string) *IntCmd { args[2+i] = value } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) RPushX(key string, value interface{}) *IntCmd { +func (c cmdable) RPushX(key string, value interface{}) *IntCmd { cmd := NewIntCmd("rpushx", key, value) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) SAdd(key string, members ...string) *IntCmd { +func (c cmdable) SAdd(key string, members ...string) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "sadd" args[1] = key @@ -872,28 +872,28 @@ func (c *commandable) SAdd(key string, members ...string) *IntCmd { args[2+i] = member } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SCard(key string) *IntCmd { +func (c cmdable) SCard(key string) *IntCmd { cmd := NewIntCmd("scard", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { args[1+i] = key } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -901,22 +901,22 @@ func (c *commandable) SDiffStore(destination string, keys ...string) *IntCmd { args[2+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { args[1+i] = key } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -924,49 +924,49 @@ func (c *commandable) SInterStore(destination string, keys ...string) *IntCmd { args[2+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SIsMember(key string, member interface{}) *BoolCmd { +func (c cmdable) SIsMember(key string, member interface{}) *BoolCmd { cmd := NewBoolCmd("sismember", key, member) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SMembers(key string) *StringSliceCmd { +func (c cmdable) SMembers(key string) *StringSliceCmd { cmd := NewStringSliceCmd("smembers", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) SPop(key string) *StringCmd { +func (c cmdable) SPop(key string) *StringCmd { cmd := NewStringCmd("spop", key) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `SRANDMEMBER key` command. -func (c *commandable) SRandMember(key string) *StringCmd { +func (c cmdable) SRandMember(key string) *StringCmd { cmd := NewStringCmd("srandmember", key) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `SRANDMEMBER key count` command. -func (c *commandable) SRandMemberN(key string, count int64) *StringSliceCmd { +func (c cmdable) SRandMemberN(key string, count int64) *StringSliceCmd { cmd := NewStringSliceCmd("srandmember", key, count) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SRem(key string, members ...string) *IntCmd { +func (c cmdable) SRem(key string, members ...string) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "srem" args[1] = key @@ -974,22 +974,22 @@ func (c *commandable) SRem(key string, members ...string) *IntCmd { args[2+i] = member } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { args[1+i] = key } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -997,7 +997,7 @@ func (c *commandable) SUnionStore(destination string, keys ...string) *IntCmd { args[2+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } @@ -1016,18 +1016,18 @@ type ZStore struct { Aggregate string } -func (c *commandable) 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 } cmd := NewIntCmd(a...) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `ZADD key score member [score member ...]` command. -func (c *commandable) 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 @@ -1035,7 +1035,7 @@ func (c *commandable) ZAdd(key string, members ...Z) *IntCmd { } // Redis `ZADD key NX score member [score member ...]` command. -func (c *commandable) 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" @@ -1043,7 +1043,7 @@ func (c *commandable) ZAddNX(key string, members ...Z) *IntCmd { } // Redis `ZADD key XX score member [score member ...]` command. -func (c *commandable) 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" @@ -1051,7 +1051,7 @@ func (c *commandable) ZAddXX(key string, members ...Z) *IntCmd { } // Redis `ZADD key CH score member [score member ...]` command. -func (c *commandable) 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" @@ -1059,7 +1059,7 @@ func (c *commandable) ZAddCh(key string, members ...Z) *IntCmd { } // Redis `ZADD key NX CH score member [score member ...]` command. -func (c *commandable) 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" @@ -1067,25 +1067,25 @@ func (c *commandable) ZAddNXCh(key string, members ...Z) *IntCmd { } // Redis `ZADD key XX CH score member [score member ...]` command. -func (c *commandable) 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 *commandable) 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 } cmd := NewFloatCmd(a...) - c.Process(cmd) + c.process(cmd) return cmd } // Redis `ZADD key INCR score member` command. -func (c *commandable) 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" @@ -1093,7 +1093,7 @@ func (c *commandable) ZIncr(key string, member Z) *FloatCmd { } // Redis `ZADD key NX INCR score member` command. -func (c *commandable) 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" @@ -1101,32 +1101,32 @@ func (c *commandable) ZIncrNX(key string, member Z) *FloatCmd { } // Redis `ZADD key XX INCR score member` command. -func (c *commandable) 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 *commandable) ZCard(key string) *IntCmd { +func (c cmdable) ZCard(key string) *IntCmd { cmd := NewIntCmd("zcard", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZCount(key, min, max string) *IntCmd { +func (c cmdable) ZCount(key, min, max string) *IntCmd { cmd := NewIntCmd("zcount", key, min, max) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -1144,11 +1144,11 @@ func (c *commandable) ZInterStore(destination string, store ZStore, keys ...stri args = append(args, "aggregate", store.Aggregate) } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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, @@ -1159,17 +1159,17 @@ func (c *commandable) zRange(key string, start, stop int64, withScores bool) *St args = append(args, "withscores") } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 *commandable) 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) + c.process(cmd) return cmd } @@ -1178,7 +1178,7 @@ type ZRangeBy struct { Offset, Count int64 } -func (c *commandable) 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") @@ -1192,19 +1192,19 @@ func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) ) } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { +func (c cmdable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { return c.zRangeBy("zrangebyscore", key, opt, false) } -func (c *commandable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { +func (c cmdable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { return c.zRangeBy("zrangebylex", key, opt, false) } -func (c *commandable) 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( @@ -1215,17 +1215,17 @@ func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceC ) } cmd := NewZSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRank(key, member string) *IntCmd { +func (c cmdable) ZRank(key, member string) *IntCmd { cmd := NewIntCmd("zrank", key, member) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRem(key string, members ...string) *IntCmd { +func (c cmdable) ZRem(key string, members ...string) *IntCmd { args := make([]interface{}, 2+len(members)) args[0] = "zrem" args[1] = key @@ -1233,40 +1233,40 @@ func (c *commandable) ZRem(key string, members ...string) *IntCmd { args[2+i] = member } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRemRangeByRank(key string, start, stop int64) *IntCmd { +func (c cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd { cmd := NewIntCmd( "zremrangebyrank", key, start, stop, ) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRemRangeByScore(key, min, max string) *IntCmd { +func (c cmdable) ZRemRangeByScore(key, min, max string) *IntCmd { cmd := NewIntCmd("zremrangebyscore", key, min, max) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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( @@ -1277,19 +1277,19 @@ func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCm ) } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { +func (c cmdable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { return c.zRevRangeBy("zrevrangebyscore", key, opt) } -func (c *commandable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { +func (c cmdable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { return c.zRevRangeBy("zrevrangebylex", key, opt) } -func (c *commandable) 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( @@ -1300,23 +1300,23 @@ func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSli ) } cmd := NewZSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZRevRank(key, member string) *IntCmd { +func (c cmdable) ZRevRank(key, member string) *IntCmd { cmd := NewIntCmd("zrevrank", key, member) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ZScore(key, member string) *FloatCmd { +func (c cmdable) ZScore(key, member string) *FloatCmd { cmd := NewFloatCmd("zscore", key, member) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -1334,13 +1334,13 @@ func (c *commandable) ZUnionStore(dest string, store ZStore, keys ...string) *In args = append(args, "aggregate", store.Aggregate) } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) PFAdd(key string, fields ...string) *IntCmd { +func (c cmdable) PFAdd(key string, fields ...string) *IntCmd { args := make([]interface{}, 2+len(fields)) args[0] = "pfadd" args[1] = key @@ -1348,22 +1348,22 @@ func (c *commandable) PFAdd(key string, fields ...string) *IntCmd { args[2+i] = field } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 { args[1+i] = key } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -1371,115 +1371,115 @@ func (c *commandable) PFMerge(dest string, keys ...string) *StatusCmd { args[2+i] = key } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) BgRewriteAOF() *StatusCmd { +func (c cmdable) BgRewriteAOF() *StatusCmd { cmd := NewStatusCmd("bgrewriteaof") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) BgSave() *StatusCmd { +func (c cmdable) BgSave() *StatusCmd { cmd := NewStatusCmd("bgsave") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClientKill(ipPort string) *StatusCmd { +func (c cmdable) ClientKill(ipPort string) *StatusCmd { cmd := NewStatusCmd("client", "kill", ipPort) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClientList() *StringCmd { +func (c cmdable) ClientList() *StringCmd { cmd := NewStringCmd("client", "list") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClientPause(dur time.Duration) *BoolCmd { +func (c cmdable) ClientPause(dur time.Duration) *BoolCmd { cmd := NewBoolCmd("client", "pause", formatMs(dur)) - c.Process(cmd) + c.process(cmd) return cmd } // ClientSetName assigns a name to the one of many connections in the pool. -func (c *commandable) ClientSetName(name string) *BoolCmd { +func (c cmdable) ClientSetName(name string) *BoolCmd { cmd := NewBoolCmd("client", "setname", name) - c.Process(cmd) + c.process(cmd) return cmd } // ClientGetName returns the name of the one of many connections in the pool. func (c *Client) ClientGetName() *StringCmd { cmd := NewStringCmd("client", "getname") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ConfigGet(parameter string) *SliceCmd { +func (c cmdable) ConfigGet(parameter string) *SliceCmd { cmd := NewSliceCmd("config", "get", parameter) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ConfigResetStat() *StatusCmd { +func (c cmdable) ConfigResetStat() *StatusCmd { cmd := NewStatusCmd("config", "resetstat") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ConfigSet(parameter, value string) *StatusCmd { +func (c cmdable) ConfigSet(parameter, value string) *StatusCmd { cmd := NewStatusCmd("config", "set", parameter, value) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) DbSize() *IntCmd { +func (c cmdable) DbSize() *IntCmd { cmd := NewIntCmd("dbsize") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) FlushAll() *StatusCmd { +func (c cmdable) FlushAll() *StatusCmd { cmd := NewStatusCmd("flushall") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) FlushDb() *StatusCmd { +func (c cmdable) FlushDb() *StatusCmd { cmd := NewStatusCmd("flushdb") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Info(section ...string) *StringCmd { +func (c cmdable) Info(section ...string) *StringCmd { args := []interface{}{"info"} if len(section) > 0 { args = append(args, section[0]) } cmd := NewStringCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) LastSave() *IntCmd { +func (c cmdable) LastSave() *IntCmd { cmd := NewIntCmd("lastsave") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) Save() *StatusCmd { +func (c cmdable) Save() *StatusCmd { cmd := NewStatusCmd("save") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) shutdown(modifier string) *StatusCmd { +func (c cmdable) shutdown(modifier string) *StatusCmd { var args []interface{} if modifier == "" { args = []interface{}{"shutdown"} @@ -1487,7 +1487,7 @@ func (c *commandable) shutdown(modifier string) *StatusCmd { args = []interface{}{"shutdown", modifier} } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) if err := cmd.Err(); err != nil { if err == io.EOF { // Server quit as expected. @@ -1501,41 +1501,41 @@ func (c *commandable) shutdown(modifier string) *StatusCmd { return cmd } -func (c *commandable) Shutdown() *StatusCmd { +func (c cmdable) Shutdown() *StatusCmd { return c.shutdown("") } -func (c *commandable) ShutdownSave() *StatusCmd { +func (c cmdable) ShutdownSave() *StatusCmd { return c.shutdown("save") } -func (c *commandable) ShutdownNoSave() *StatusCmd { +func (c cmdable) ShutdownNoSave() *StatusCmd { return c.shutdown("nosave") } -func (c *commandable) SlaveOf(host, port string) *StatusCmd { +func (c cmdable) SlaveOf(host, port string) *StatusCmd { cmd := NewStatusCmd("slaveof", host, port) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) SlowLog() { +func (c cmdable) SlowLog() { panic("not implemented") } -func (c *commandable) Sync() { +func (c cmdable) Sync() { panic("not implemented") } -func (c *commandable) Time() *StringSliceCmd { +func (c cmdable) Time() *StringSliceCmd { cmd := NewStringSliceCmd("time") - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) 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 @@ -1548,11 +1548,11 @@ func (c *commandable) Eval(script string, keys []string, args ...interface{}) *C cmdArgs[pos+i] = arg } cmd := NewCmd(cmdArgs...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -1565,11 +1565,11 @@ func (c *commandable) EvalSha(sha1 string, keys []string, args ...interface{}) * cmdArgs[pos+i] = arg } cmd := NewCmd(cmdArgs...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ScriptExists(scripts ...string) *BoolSliceCmd { +func (c cmdable) ScriptExists(scripts ...string) *BoolSliceCmd { args := make([]interface{}, 2+len(scripts)) args[0] = "script" args[1] = "exists" @@ -1577,49 +1577,49 @@ func (c *commandable) ScriptExists(scripts ...string) *BoolSliceCmd { args[2+i] = script } cmd := NewBoolSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ScriptFlush() *StatusCmd { +func (c cmdable) ScriptFlush() *StatusCmd { cmd := NewStatusCmd("script", "flush") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ScriptKill() *StatusCmd { +func (c cmdable) ScriptKill() *StatusCmd { cmd := NewStatusCmd("script", "kill") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ScriptLoad(script string) *StringCmd { +func (c cmdable) ScriptLoad(script string) *StringCmd { cmd := NewStringCmd("script", "load", script) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) DebugObject(key string) *StringCmd { +func (c cmdable) DebugObject(key string) *StringCmd { cmd := NewStringCmd("debug", "object", key) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) PubSubChannels(pattern string) *StringSliceCmd { +func (c cmdable) PubSubChannels(pattern string) *StringSliceCmd { args := []interface{}{"pubsub", "channels"} if pattern != "*" { args = append(args, pattern) } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) PubSubNumSub(channels ...string) *StringIntMapCmd { +func (c cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd { args := make([]interface{}, 2+len(channels)) args[0] = "pubsub" args[1] = "numsub" @@ -1627,85 +1627,85 @@ func (c *commandable) PubSubNumSub(channels ...string) *StringIntMapCmd { args[2+i] = channel } cmd := NewStringIntMapCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) PubSubNumPat() *IntCmd { +func (c cmdable) PubSubNumPat() *IntCmd { cmd := NewIntCmd("pubsub", "numpat") - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) ClusterSlots() *ClusterSlotsCmd { +func (c cmdable) ClusterSlots() *ClusterSlotsCmd { cmd := NewClusterSlotsCmd("cluster", "slots") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterNodes() *StringCmd { +func (c cmdable) ClusterNodes() *StringCmd { cmd := NewStringCmd("cluster", "nodes") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterMeet(host, port string) *StatusCmd { +func (c cmdable) ClusterMeet(host, port string) *StatusCmd { cmd := NewStatusCmd("cluster", "meet", host, port) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterForget(nodeID string) *StatusCmd { +func (c cmdable) ClusterForget(nodeID string) *StatusCmd { cmd := NewStatusCmd("cluster", "forget", nodeID) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterReplicate(nodeID string) *StatusCmd { +func (c cmdable) ClusterReplicate(nodeID string) *StatusCmd { cmd := NewStatusCmd("cluster", "replicate", nodeID) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterResetSoft() *StatusCmd { +func (c cmdable) ClusterResetSoft() *StatusCmd { cmd := NewStatusCmd("cluster", "reset", "soft") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterResetHard() *StatusCmd { +func (c cmdable) ClusterResetHard() *StatusCmd { cmd := NewStatusCmd("cluster", "reset", "hard") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterInfo() *StringCmd { +func (c cmdable) ClusterInfo() *StringCmd { cmd := NewStringCmd("cluster", "info") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterKeySlot(key string) *IntCmd { +func (c cmdable) ClusterKeySlot(key string) *IntCmd { cmd := NewIntCmd("cluster", "keyslot", key) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterCountFailureReports(nodeID string) *IntCmd { +func (c cmdable) ClusterCountFailureReports(nodeID string) *IntCmd { cmd := NewIntCmd("cluster", "count-failure-reports", nodeID) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterCountKeysInSlot(slot int) *IntCmd { +func (c cmdable) ClusterCountKeysInSlot(slot int) *IntCmd { cmd := NewIntCmd("cluster", "countkeysinslot", slot) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterDelSlots(slots ...int) *StatusCmd { +func (c cmdable) ClusterDelSlots(slots ...int) *StatusCmd { args := make([]interface{}, 2+len(slots)) args[0] = "cluster" args[1] = "delslots" @@ -1713,11 +1713,11 @@ func (c *commandable) ClusterDelSlots(slots ...int) *StatusCmd { args[2+i] = slot } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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++ { @@ -1726,37 +1726,37 @@ func (c *commandable) ClusterDelSlotsRange(min, max int) *StatusCmd { return c.ClusterDelSlots(slots...) } -func (c *commandable) ClusterSaveConfig() *StatusCmd { +func (c cmdable) ClusterSaveConfig() *StatusCmd { cmd := NewStatusCmd("cluster", "saveconfig") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterSlaves(nodeID string) *StringSliceCmd { +func (c cmdable) ClusterSlaves(nodeID string) *StringSliceCmd { cmd := NewStringSliceCmd("cluster", "slaves", nodeID) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ReadOnly() *StatusCmd { +func (c statefulCmdable) ReadOnly() *StatusCmd { cmd := NewStatusCmd("readonly") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ReadWrite() *StatusCmd { +func (c statefulCmdable) ReadWrite() *StatusCmd { cmd := NewStatusCmd("readwrite") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterFailover() *StatusCmd { +func (c cmdable) ClusterFailover() *StatusCmd { cmd := NewStatusCmd("cluster", "failover") - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) ClusterAddSlots(slots ...int) *StatusCmd { +func (c cmdable) ClusterAddSlots(slots ...int) *StatusCmd { args := make([]interface{}, 2+len(slots)) args[0] = "cluster" args[1] = "addslots" @@ -1764,11 +1764,11 @@ func (c *commandable) ClusterAddSlots(slots ...int) *StatusCmd { args[2+i] = strconv.Itoa(num) } cmd := NewStatusCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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++ { @@ -1779,7 +1779,7 @@ func (c *commandable) ClusterAddSlotsRange(min, max int) *StatusCmd { //------------------------------------------------------------------------------ -func (c *commandable) 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 @@ -1789,32 +1789,32 @@ func (c *commandable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd { args[2+3*i+2] = eachLoc.Name } cmd := NewIntCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) 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) + c.process(cmd) return cmd } -func (c *commandable) GeoDist(key string, member1, member2, unit string) *FloatCmd { +func (c cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd { if unit == "" { unit = "km" } cmd := NewFloatCmd("geodist", key, member1, member2, unit) - c.Process(cmd) + c.process(cmd) return cmd } -func (c *commandable) 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 @@ -1822,14 +1822,14 @@ func (c *commandable) GeoHash(key string, members ...string) *StringSliceCmd { args[2+i] = member } cmd := NewStringSliceCmd(args...) - c.Process(cmd) + c.process(cmd) return cmd } //------------------------------------------------------------------------------ -func (c *commandable) Command() *CommandsInfoCmd { +func (c cmdable) Command() *CommandsInfoCmd { cmd := NewCommandsInfoCmd("command") - c.Process(cmd) + c.process(cmd) return cmd } diff --git a/commands_test.go b/commands_test.go index 9d65f96..466f991 100644 --- a/commands_test.go +++ b/commands_test.go @@ -26,11 +26,11 @@ var _ = Describe("Commands", func() { Describe("server", func() { - It("should Auth", func() { - auth := client.Auth("password") - Expect(auth.Err()).To(MatchError("ERR Client sent AUTH, but no password is set")) - Expect(auth.Val()).To(Equal("")) - }) + // It("should Auth", func() { + // auth := client.Auth("password") + // Expect(auth.Err()).To(MatchError("ERR Client sent AUTH, but no password is set")) + // Expect(auth.Val()).To(Equal("")) + // }) It("should Echo", func() { echo := client.Echo("hello") @@ -44,11 +44,11 @@ var _ = Describe("Commands", func() { Expect(ping.Val()).To(Equal("PONG")) }) - It("should Select", func() { - sel := client.Select(1) - Expect(sel.Err()).NotTo(HaveOccurred()) - Expect(sel.Val()).To(Equal("OK")) - }) + // It("should Select", func() { + // sel := client.Select(1) + // Expect(sel.Err()).NotTo(HaveOccurred()) + // Expect(sel.Val()).To(Equal("OK")) + // }) It("should BgRewriteAOF", func() { Skip("flaky test") @@ -309,15 +309,14 @@ var _ = Describe("Commands", func() { Expect(get.Err()).To(Equal(redis.Nil)) Expect(get.Val()).To(Equal("")) - sel := client.Select(2) - Expect(sel.Err()).NotTo(HaveOccurred()) - Expect(sel.Val()).To(Equal("OK")) + pipe := client.Pipeline() + pipe.Select(2) + get = pipe.Get("key") + pipe.FlushDb() - get = client.Get("key") - Expect(get.Err()).NotTo(HaveOccurred()) + _, err := pipe.Exec() + Expect(err).NotTo(HaveOccurred()) Expect(get.Val()).To(Equal("hello")) - Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) - Expect(client.Select(1).Err()).NotTo(HaveOccurred()) }) It("should Object", func() { diff --git a/iterator.go b/iterator.go index c57c5af..0219ab4 100644 --- a/iterator.go +++ b/iterator.go @@ -3,7 +3,7 @@ package redis import "sync" type Scanner struct { - client *commandable + client cmdable *ScanCmd } @@ -54,7 +54,7 @@ func (it *ScanIterator) Next() bool { // Fetch next page. it.ScanCmd._args[1] = it.ScanCmd.cursor it.ScanCmd.reset() - it.client.Process(it.ScanCmd) + it.client.process(it.ScanCmd) if it.ScanCmd.Err() != nil { return false } diff --git a/options.go b/options.go index e1c0403..e3db4ad 100644 --- a/options.go +++ b/options.go @@ -22,7 +22,7 @@ type Options struct { // requirepass server configuration option. Password string // A database to be selected after connecting to server. - DB int64 + DB int // The maximum number of retries before giving up. // Default is to not retry failed commands. diff --git a/pipeline.go b/pipeline.go index fcddc61..8d2d884 100644 --- a/pipeline.go +++ b/pipeline.go @@ -11,7 +11,8 @@ import ( // http://redis.io/topics/pipelining. It's safe for concurrent use // by multiple goroutines. type Pipeline struct { - commandable + cmdable + statefulCmdable exec func([]Cmder) error @@ -21,7 +22,7 @@ type Pipeline struct { closed int32 } -func (pipe *Pipeline) process(cmd Cmder) { +func (pipe *Pipeline) Process(cmd Cmder) { pipe.mu.Lock() pipe.cmds = append(pipe.cmds, cmd) pipe.mu.Unlock() diff --git a/pubsub.go b/pubsub.go index aef4a76..5bbda59 100644 --- a/pubsub.go +++ b/pubsub.go @@ -20,7 +20,7 @@ func (c *Client) Publish(channel, message string) *IntCmd { // http://redis.io/topics/pubsub. It's NOT safe for concurrent use by // multiple goroutines. type PubSub struct { - base *baseClient + base baseClient channels []string patterns []string @@ -31,7 +31,7 @@ type PubSub struct { // Deprecated. Use Subscribe/PSubscribe instead. func (c *Client) PubSub() *PubSub { return &PubSub{ - base: &baseClient{ + base: baseClient{ opt: c.opt, connPool: pool.NewStickyConnPool(c.connPool.(*pool.ConnPool), false), }, diff --git a/race_test.go b/race_test.go index f654f87..75ade87 100644 --- a/race_test.go +++ b/race_test.go @@ -172,7 +172,7 @@ var _ = Describe("races", func() { perform(C, func(id int) { opt := redisOptions() - opt.DB = int64(id) + opt.DB = id client := redis.NewClient(opt) for i := 0; i < N; i++ { err := client.Set("db", id, 0).Err() @@ -194,7 +194,7 @@ var _ = Describe("races", func() { It("should select DB with read timeout", func() { perform(C, func(id int) { opt := redisOptions() - opt.DB = int64(id) + opt.DB = id opt.ReadTimeout = time.Nanosecond client := redis.NewClient(opt) diff --git a/redis.go b/redis.go index bb9fcd0..d44e86e 100644 --- a/redis.go +++ b/redis.go @@ -56,29 +56,25 @@ func (c *baseClient) initConn(cn *pool.Conn) error { // Temp client for Auth and Select. client := newClient(c.opt, pool.NewSingleConnPool(cn)) - - if c.opt.Password != "" { - if err := client.Auth(c.opt.Password).Err(); err != nil { - return err + _, err := client.Pipelined(func(pipe *Pipeline) error { + if c.opt.Password != "" { + pipe.Auth(c.opt.Password) } - } - if c.opt.DB > 0 { - if err := client.Select(c.opt.DB).Err(); err != nil { - return err + if c.opt.DB > 0 { + pipe.Select(c.opt.DB) } - } - if c.opt.ReadOnly { - if err := client.ReadOnly().Err(); err != nil { - return err + if c.opt.ReadOnly { + pipe.ReadOnly() } - } - return nil + return nil + }) + return err } -func (c *baseClient) process(cmd Cmder) { +func (c *baseClient) Process(cmd Cmder) { for i := 0; i <= c.opt.MaxRetries; i++ { if i > 0 { cmd.reset() @@ -145,16 +141,14 @@ func (c *baseClient) Close() error { // goroutines. type Client struct { baseClient - commandable + cmdable } func newClient(opt *Options, pool pool.Pooler) *Client { base := baseClient{opt: opt, connPool: pool} client := &Client{ baseClient: base, - commandable: commandable{ - process: base.process, - }, + cmdable: cmdable{base.Process}, } return client } @@ -178,11 +172,12 @@ func (c *Client) PoolStats() *PoolStats { } func (c *Client) Pipeline() *Pipeline { - pipe := &Pipeline{ + pipe := Pipeline{ exec: c.pipelineExec, } - pipe.commandable.process = pipe.process - return pipe + pipe.cmdable.process = pipe.Process + pipe.statefulCmdable.process = pipe.Process + return &pipe } func (c *Client) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) { diff --git a/ring.go b/ring.go index 31559e6..17f5305 100644 --- a/ring.go +++ b/ring.go @@ -24,7 +24,7 @@ type RingOptions struct { // Following options are copied from Options struct. - DB int64 + DB int Password string MaxRetries int @@ -110,7 +110,7 @@ func (shard *ringShard) Vote(up bool) bool { // and can tolerate losing data when one of the servers dies. // Otherwise you should use Redis Cluster. type Ring struct { - commandable + cmdable opt *RingOptions nreplicas int @@ -136,7 +136,7 @@ func NewRing(opt *RingOptions) *Ring { cmdsInfoOnce: new(sync.Once), } - ring.commandable.process = ring.process + ring.cmdable.process = ring.Process for name, addr := range opt.Addrs { clopt := opt.clientOptions() clopt.Addr = addr @@ -196,13 +196,13 @@ func (ring *Ring) getClient(key string) (*Client, error) { return cl, nil } -func (ring *Ring) process(cmd Cmder) { +func (ring *Ring) Process(cmd Cmder) { cl, err := ring.getClient(ring.cmdFirstKey(cmd)) if err != nil { cmd.setErr(err) return } - cl.baseClient.process(cmd) + cl.baseClient.Process(cmd) } // rebalance removes dead shards from the ring. @@ -273,11 +273,12 @@ func (ring *Ring) Close() (retErr error) { } func (ring *Ring) Pipeline() *Pipeline { - pipe := &Pipeline{ + pipe := Pipeline{ exec: ring.pipelineExec, } - pipe.commandable.process = pipe.process - return pipe + pipe.cmdable.process = pipe.Process + pipe.statefulCmdable.process = pipe.Process + return &pipe } func (ring *Ring) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) { diff --git a/sentinel.go b/sentinel.go index 53c40a9..6cd3986 100644 --- a/sentinel.go +++ b/sentinel.go @@ -25,7 +25,7 @@ type FailoverOptions struct { // Following options are copied from Options struct. Password string - DB int64 + DB int MaxRetries int @@ -70,43 +70,41 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client { opt: opt, } - base := baseClient{ - opt: opt, - connPool: failover.Pool(), + client := Client{ + baseClient: baseClient{ + opt: opt, + connPool: failover.Pool(), - onClose: func() error { - return failover.Close() - }, - } - return &Client{ - baseClient: base, - commandable: commandable{ - process: base.process, + onClose: func() error { + return failover.Close() + }, }, } + client.cmdable.process = client.Process + return &client } //------------------------------------------------------------------------------ type sentinelClient struct { + cmdable baseClient - commandable } func newSentinel(opt *Options) *sentinelClient { - base := baseClient{ - opt: opt, - connPool: newConnPool(opt), - } - return &sentinelClient{ - baseClient: base, - commandable: commandable{process: base.process}, + client := sentinelClient{ + baseClient: baseClient{ + opt: opt, + connPool: newConnPool(opt), + }, } + client.cmdable = cmdable{client.Process} + return &client } func (c *sentinelClient) PubSub() *PubSub { return &PubSub{ - base: &baseClient{ + base: baseClient{ opt: c.opt, connPool: pool.NewStickyConnPool(c.connPool.(*pool.ConnPool), false), }, diff --git a/tx.go b/tx.go index 34e828b..43271fa 100644 --- a/tx.go +++ b/tx.go @@ -15,23 +15,24 @@ var errDiscard = errors.New("redis: Discard can be used only inside Exec") // by multiple goroutines, because Exec resets list of watched keys. // If you don't need WATCH it is better to use Pipeline. type Tx struct { - commandable - - base *baseClient + cmdable + statefulCmdable + baseClient cmds []Cmder closed bool } func (c *Client) newTx() *Tx { - tx := &Tx{ - base: &baseClient{ + tx := Tx{ + baseClient: baseClient{ opt: c.opt, connPool: pool.NewStickyConnPool(c.connPool.(*pool.ConnPool), true), }, } - tx.commandable.process = tx.process - return tx + tx.cmdable.process = tx.Process + tx.statefulCmdable.process = tx.Process + return &tx } func (c *Client) Watch(fn func(*Tx) error, keys ...string) error { @@ -49,9 +50,9 @@ func (c *Client) Watch(fn func(*Tx) error, keys ...string) error { return retErr } -func (tx *Tx) process(cmd Cmder) { +func (tx *Tx) Process(cmd Cmder) { if tx.cmds == nil { - tx.base.process(cmd) + tx.baseClient.Process(cmd) } else { tx.cmds = append(tx.cmds, cmd) } @@ -66,7 +67,7 @@ func (tx *Tx) close() error { if err := tx.Unwatch().Err(); err != nil { internal.Logf("Unwatch failed: %s", err) } - return tx.base.Close() + return tx.baseClient.Close() } // Watch marks the keys to be watched for conditional execution @@ -133,14 +134,14 @@ func (tx *Tx) MultiExec(fn func() error) ([]Cmder, error) { // Strip MULTI and EXEC commands. retCmds := cmds[1 : len(cmds)-1] - cn, err := tx.base.conn() + cn, err := tx.conn() if err != nil { setCmdsErr(retCmds, err) return retCmds, err } err = tx.execCmds(cn, cmds) - tx.base.putConn(cn, err, false) + tx.putConn(cn, err, false) return retCmds, err }