@@ -708,7 +708,6 @@ type ClusterClient struct {
708708 * clusterClient
709709 cmdable
710710 hooks
711- ctx context.Context
712711}
713712
714713// NewClusterClient returns a Redis Cluster client as described in
@@ -721,7 +720,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
721720 opt : opt ,
722721 nodes : newClusterNodes (opt ),
723722 },
724- ctx : context .Background (),
725723 }
726724 c .state = newClusterStateHolder (c .loadState )
727725 c .cmdsInfoCache = newCmdsInfoCache (c .cmdsInfo )
@@ -765,8 +763,8 @@ func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error {
765763}
766764
767765func (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 )
770768
771769 var node * clusterNode
772770 var ask bool
@@ -1141,9 +1139,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11411139 return err
11421140 }
11431141
1144- if c .opt .ReadOnly && c .cmdsAreReadOnly (cmds ) {
1142+ if c .opt .ReadOnly && c .cmdsAreReadOnly (ctx , cmds ) {
11451143 for _ , cmd := range cmds {
1146- slot := c .cmdSlot (cmd )
1144+ slot := c .cmdSlot (ctx , cmd )
11471145 node , err := c .slotReadOnlyNode (state , slot )
11481146 if err != nil {
11491147 return err
@@ -1154,7 +1152,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11541152 }
11551153
11561154 for _ , cmd := range cmds {
1157- slot := c .cmdSlot (cmd )
1155+ slot := c .cmdSlot (ctx , cmd )
11581156 node , err := state .slotMasterNode (slot )
11591157 if err != nil {
11601158 return err
@@ -1164,9 +1162,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11641162 return nil
11651163}
11661164
1167- func (c * ClusterClient ) cmdsAreReadOnly (cmds []Cmder ) bool {
1165+ func (c * ClusterClient ) cmdsAreReadOnly (ctx context. Context , cmds []Cmder ) bool {
11681166 for _ , cmd := range cmds {
1169- cmdInfo := c .cmdInfo (cmd .Name ())
1167+ cmdInfo := c .cmdInfo (ctx , cmd .Name ())
11701168 if cmdInfo == nil || ! cmdInfo .ReadOnly {
11711169 return false
11721170 }
@@ -1278,7 +1276,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
12781276 return err
12791277 }
12801278
1281- cmdsMap := c .mapCmdsBySlot (cmds )
1279+ cmdsMap := c .mapCmdsBySlot (ctx , cmds )
12821280 for slot , cmds := range cmdsMap {
12831281 node , err := state .slotMasterNode (slot )
12841282 if err != nil {
@@ -1329,10 +1327,10 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
13291327 return cmdsFirstErr (cmds )
13301328}
13311329
1332- func (c * ClusterClient ) mapCmdsBySlot (cmds []Cmder ) map [int ][]Cmder {
1330+ func (c * ClusterClient ) mapCmdsBySlot (ctx context. Context , cmds []Cmder ) map [int ][]Cmder {
13331331 cmdsMap := make (map [int ][]Cmder )
13341332 for _ , cmd := range cmds {
1335- slot := c .cmdSlot (cmd )
1333+ slot := c .cmdSlot (ctx , cmd )
13361334 cmdsMap [slot ] = append (cmdsMap [slot ], cmd )
13371335 }
13381336 return cmdsMap
@@ -1602,8 +1600,8 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo,
16021600 return nil , firstErr
16031601}
16041602
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 )
16071605 if err != nil {
16081606 internal .Logger .Printf (context .TODO (), "getting command info: %s" , err )
16091607 return nil
@@ -1616,13 +1614,13 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
16161614 return info
16171615}
16181616
1619- func (c * ClusterClient ) cmdSlot (cmd Cmder ) int {
1617+ func (c * ClusterClient ) cmdSlot (ctx context. Context , cmd Cmder ) int {
16201618 args := cmd .Args ()
16211619 if args [0 ] == "cluster" && args [1 ] == "getkeysinslot" {
16221620 return args [2 ].(int )
16231621 }
16241622
1625- cmdInfo := c .cmdInfo (cmd .Name ())
1623+ cmdInfo := c .cmdInfo (ctx , cmd .Name ())
16261624 return cmdSlot (cmd , cmdFirstKeyPos (cmd , cmdInfo ))
16271625}
16281626
0 commit comments