@@ -2,6 +2,7 @@ package redis
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "reflect"
78 "strings"
@@ -12,6 +13,14 @@ import (
1213 "github.com/redis/go-redis/v9/internal/routing"
1314)
1415
16+ var (
17+ errInvalidCmdPointer = errors .New ("redis: invalid command pointer" )
18+ errNoCmdsToAggregate = errors .New ("redis: no commands to aggregate" )
19+ errNoResToAggregate = errors .New ("redis: no results to aggregate" )
20+ errInvalidCursorCmdArgsCount = errors .New ("redis: FT.CURSOR command requires at least 3 arguments" )
21+ errInvalidCursorIdType = errors .New ("redis: invalid cursor ID type" )
22+ )
23+
1524// slotResult represents the result of executing a command on a specific slot
1625type slotResult struct {
1726 cmd Cmder
@@ -275,12 +284,12 @@ func (c *ClusterClient) executeSpecialCommand(ctx context.Context, cmd Cmder, po
275284func (c * ClusterClient ) executeCursorCommand (ctx context.Context , cmd Cmder ) error {
276285 args := cmd .Args ()
277286 if len (args ) < 4 {
278- return fmt . Errorf ( "redis: FT.CURSOR command requires at least 3 arguments" )
287+ return errInvalidCursorCmdArgsCount
279288 }
280289
281290 cursorID , ok := args [3 ].(string )
282291 if ! ok {
283- return fmt . Errorf ( "redis: invalid cursor ID type" )
292+ return errInvalidCursorIdType
284293 }
285294
286295 // Route based on cursor ID to maintain stickiness
@@ -394,7 +403,7 @@ func (c *ClusterClient) aggregateMultiSlotResults(ctx context.Context, cmd Cmder
394403// aggregateKeyedValues aggregates individual key-value pairs while preserving key order
395404func (c * ClusterClient ) aggregateKeyedValues (cmd Cmder , keyedResults map [string ]routing.AggregatorResErr , keyOrder []string , policy * routing.CommandPolicy ) error {
396405 if len (keyedResults ) == 0 {
397- return fmt . Errorf ( "redis: no results to aggregate" )
406+ return errNoResToAggregate
398407 }
399408
400409 aggregator := c .createAggregator (policy , cmd , true )
@@ -419,7 +428,7 @@ func (c *ClusterClient) aggregateKeyedValues(cmd Cmder, keyedResults map[string]
419428// aggregateResponses aggregates multiple shard responses
420429func (c * ClusterClient ) aggregateResponses (cmd Cmder , cmds []Cmder , policy * routing.CommandPolicy ) error {
421430 if len (cmds ) == 0 {
422- return fmt . Errorf ( "redis: no commands to aggregate" )
431+ return errNoCmdsToAggregate
423432 }
424433
425434 if len (cmds ) == 1 {
@@ -958,7 +967,7 @@ func (c *ClusterClient) setCommandValue(cmd Cmder, value interface{}) error {
958967func (c * ClusterClient ) setCommandValueReflection (cmd Cmder , value interface {}) error {
959968 cmdValue := reflect .ValueOf (cmd )
960969 if cmdValue .Kind () != reflect .Ptr || cmdValue .IsNil () {
961- return fmt . Errorf ( "redis: invalid command pointer" )
970+ return errInvalidCmdPointer
962971 }
963972
964973 setValMethod := cmdValue .MethodByName ("SetVal" )
0 commit comments