Skip to content

Commit

Permalink
feat: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulPancake committed Jun 19, 2024
1 parent 157c8e1 commit 61eeffa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 1 addition & 4 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,10 +1053,7 @@ func (c *clusterClient) Dedicate() (DedicatedClient, func()) {
func (c *clusterClient) Nodes() map[string]Client {
c.mu.RLock()
nodes := make(map[string]Client, len(c.conns))
disableCache := false
if (c.opt != nil && c.opt.DisableCache) || (c.rOpt != nil && c.rOpt.DisableCache) {
disableCache = true
}
disableCache := c.opt != nil && c.opt.DisableCache
for addr, cc := range c.conns {
nodes[addr] = newSingleClientWithConn(cc.conn, c.cmd, c.retry, disableCache)
}
Expand Down
11 changes: 11 additions & 0 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ func TestMGetCache(t *testing.T) {
if err != nil {
t.Fatalf("unexpected err %v", err)
}
disableCacheClient, err := newSingleClient(&ClientOption{InitAddress: []string{""}, DisableCache: true}, m, func(dst string, opt *ClientOption) conn {
return m
})
if err != nil {
t.Fatalf("unexpected err %v", err)
}
t.Run("DisableCache", func(t *testing.T) {
if v, err := MGetCache(disableCacheClient, context.Background(), 100, []string{"1", "2"}); err != nil || v == nil {
t.Fatalf("unexpected response %v %v", v, err)
}
})
t.Run("Delegate DoCache", func(t *testing.T) {
m.DoMultiCacheFn = func(multi ...CacheableTTL) *redisresults {
if reflect.DeepEqual(multi[0].Cmd.Commands(), []string{"GET", "1"}) && multi[0].TTL == 100 &&
Expand Down
5 changes: 1 addition & 4 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ func (c *sentinelClient) Dedicate() (DedicatedClient, func()) {

func (c *sentinelClient) Nodes() map[string]Client {
conn := c.mConn.Load().(conn)
disableCache := false
if (c.mOpt != nil && c.mOpt.DisableCache) || (c.sOpt != nil && c.sOpt.DisableCache) {
disableCache = true
}
disableCache := c.mOpt != nil && c.mOpt.DisableCache
return map[string]Client{conn.Addr(): newSingleClientWithConn(conn, c.cmd, c.retry, disableCache)}
}

Expand Down

0 comments on commit 61eeffa

Please sign in to comment.