@@ -708,7 +708,6 @@ type ClusterClient struct {
708
708
* clusterClient
709
709
cmdable
710
710
hooks
711
- ctx context.Context
712
711
}
713
712
714
713
// NewClusterClient returns a Redis Cluster client as described in
@@ -721,7 +720,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
721
720
opt : opt ,
722
721
nodes : newClusterNodes (opt ),
723
722
},
724
- ctx : context .Background (),
725
723
}
726
724
c .state = newClusterStateHolder (c .loadState )
727
725
c .cmdsInfoCache = newCmdsInfoCache (c .cmdsInfo )
@@ -765,8 +763,8 @@ func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error {
765
763
}
766
764
767
765
func (c * ClusterClient ) process (ctx context.Context , cmd Cmder ) error {
768
- cmdInfo := c .cmdInfo (cmd .Name ())
769
- slot := c .cmdSlot (cmd )
766
+ cmdInfo := c .cmdInfo (ctx , cmd .Name ())
767
+ slot := c .cmdSlot (ctx , cmd )
770
768
771
769
var node * clusterNode
772
770
var ask bool
@@ -1141,9 +1139,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
1141
1139
return err
1142
1140
}
1143
1141
1144
- if c .opt .ReadOnly && c .cmdsAreReadOnly (cmds ) {
1142
+ if c .opt .ReadOnly && c .cmdsAreReadOnly (ctx , cmds ) {
1145
1143
for _ , cmd := range cmds {
1146
- slot := c .cmdSlot (cmd )
1144
+ slot := c .cmdSlot (ctx , cmd )
1147
1145
node , err := c .slotReadOnlyNode (state , slot )
1148
1146
if err != nil {
1149
1147
return err
@@ -1154,7 +1152,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
1154
1152
}
1155
1153
1156
1154
for _ , cmd := range cmds {
1157
- slot := c .cmdSlot (cmd )
1155
+ slot := c .cmdSlot (ctx , cmd )
1158
1156
node , err := state .slotMasterNode (slot )
1159
1157
if err != nil {
1160
1158
return err
@@ -1164,9 +1162,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
1164
1162
return nil
1165
1163
}
1166
1164
1167
- func (c * ClusterClient ) cmdsAreReadOnly (cmds []Cmder ) bool {
1165
+ func (c * ClusterClient ) cmdsAreReadOnly (ctx context. Context , cmds []Cmder ) bool {
1168
1166
for _ , cmd := range cmds {
1169
- cmdInfo := c .cmdInfo (cmd .Name ())
1167
+ cmdInfo := c .cmdInfo (ctx , cmd .Name ())
1170
1168
if cmdInfo == nil || ! cmdInfo .ReadOnly {
1171
1169
return false
1172
1170
}
@@ -1278,7 +1276,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
1278
1276
return err
1279
1277
}
1280
1278
1281
- cmdsMap := c .mapCmdsBySlot (cmds )
1279
+ cmdsMap := c .mapCmdsBySlot (ctx , cmds )
1282
1280
for slot , cmds := range cmdsMap {
1283
1281
node , err := state .slotMasterNode (slot )
1284
1282
if err != nil {
@@ -1329,10 +1327,10 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
1329
1327
return cmdsFirstErr (cmds )
1330
1328
}
1331
1329
1332
- func (c * ClusterClient ) mapCmdsBySlot (cmds []Cmder ) map [int ][]Cmder {
1330
+ func (c * ClusterClient ) mapCmdsBySlot (ctx context. Context , cmds []Cmder ) map [int ][]Cmder {
1333
1331
cmdsMap := make (map [int ][]Cmder )
1334
1332
for _ , cmd := range cmds {
1335
- slot := c .cmdSlot (cmd )
1333
+ slot := c .cmdSlot (ctx , cmd )
1336
1334
cmdsMap [slot ] = append (cmdsMap [slot ], cmd )
1337
1335
}
1338
1336
return cmdsMap
@@ -1602,8 +1600,8 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo,
1602
1600
return nil , firstErr
1603
1601
}
1604
1602
1605
- func (c * ClusterClient ) cmdInfo (name string ) * CommandInfo {
1606
- cmdsInfo , err := c .cmdsInfoCache .Get (c . ctx )
1603
+ func (c * ClusterClient ) cmdInfo (ctx context. Context , name string ) * CommandInfo {
1604
+ cmdsInfo , err := c .cmdsInfoCache .Get (ctx )
1607
1605
if err != nil {
1608
1606
internal .Logger .Printf (context .TODO (), "getting command info: %s" , err )
1609
1607
return nil
@@ -1616,13 +1614,13 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
1616
1614
return info
1617
1615
}
1618
1616
1619
- func (c * ClusterClient ) cmdSlot (cmd Cmder ) int {
1617
+ func (c * ClusterClient ) cmdSlot (ctx context. Context , cmd Cmder ) int {
1620
1618
args := cmd .Args ()
1621
1619
if args [0 ] == "cluster" && args [1 ] == "getkeysinslot" {
1622
1620
return args [2 ].(int )
1623
1621
}
1624
1622
1625
- cmdInfo := c .cmdInfo (cmd .Name ())
1623
+ cmdInfo := c .cmdInfo (ctx , cmd .Name ())
1626
1624
return cmdSlot (cmd , cmdFirstKeyPos (cmd , cmdInfo ))
1627
1625
}
1628
1626
0 commit comments