@@ -34,6 +34,13 @@ func (c *ClusterClient) routeAndRun(ctx context.Context, cmd Cmder, node *cluste
3434 policy = c .cmdInfoResolver .GetCommandPolicy (ctx , cmd )
3535 }
3636
37+ // Set stepCount from cmdInfo if not already set
38+ if cmd .stepCount () == 0 {
39+ if cmdInfo := c .cmdInfo (ctx , cmd .Name ()); cmdInfo != nil && cmdInfo .StepCount > 0 {
40+ cmd .SetStepCount (cmdInfo .StepCount )
41+ }
42+ }
43+
3744 if policy == nil {
3845 return c .executeDefault (ctx , cmd , policy , node )
3946 }
@@ -104,6 +111,10 @@ func (c *ClusterClient) executeOnAllShards(ctx context.Context, cmd Cmder, polic
104111func (c * ClusterClient ) executeMultiShard (ctx context.Context , cmd Cmder , policy * routing.CommandPolicy ) error {
105112 args := cmd .Args ()
106113 firstKeyPos := int (cmdFirstKeyPos (cmd ))
114+ stepCount := int (cmd .stepCount ())
115+ if stepCount == 0 {
116+ stepCount = 1 // Default to 1 if not set
117+ }
107118
108119 if firstKeyPos == 0 || firstKeyPos >= len (args ) {
109120 return fmt .Errorf ("redis: multi-shard command %s has no key arguments" , cmd .Name ())
@@ -113,14 +124,20 @@ func (c *ClusterClient) executeMultiShard(ctx context.Context, cmd Cmder, policy
113124 slotMap := make (map [int ][]string )
114125 keyOrder := make ([]string , 0 )
115126
116- for i := firstKeyPos ; i < len (args ); i ++ {
127+ for i := firstKeyPos ; i < len (args ); i += stepCount {
117128 key , ok := args [i ].(string )
118129 if ! ok {
119130 return fmt .Errorf ("redis: non-string key at position %d: %v" , i , args [i ])
120131 }
121132
122133 slot := hashtag .Slot (key )
123134 slotMap [slot ] = append (slotMap [slot ], key )
135+ for j := 1 ; j < stepCount ; j ++ {
136+ if i + j >= len (args ) {
137+ break
138+ }
139+ slotMap [slot ] = append (slotMap [slot ], args [i + j ].(string ))
140+ }
124141 keyOrder = append (keyOrder , key )
125142 }
126143
@@ -371,6 +388,7 @@ func (c *ClusterClient) aggregateMultiSlotResults(ctx context.Context, cmd Cmder
371388 }
372389 }
373390
391+ // TODO: return multiple errors by order when we will implement multiple errors returning
374392 if result .err != nil {
375393 firstErr = result .err
376394 }
0 commit comments