Skip to content

Commit ec36741

Browse files
change func signature from cmdName to cmder
1 parent ec3fc78 commit ec36741

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

command_policy_resolver.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,21 @@ var defaultPolicies = map[module]map[commandName]*routing.CommandPolicy{
118118
}
119119

120120
type CommandInfoResolver struct {
121-
resolve func(ctx context.Context, cmdName string) *routing.CommandPolicy
121+
resolve func(ctx context.Context, cmd Cmder) *routing.CommandPolicy
122122
fallBackResolver *CommandInfoResolver
123123
}
124124

125-
func NewCommandInfoResolver(resolver func(ctx context.Context, cmdName string) *routing.CommandPolicy) *CommandInfoResolver {
125+
func NewCommandInfoResolver(resolver func(ctx context.Context, cmd Cmder) *routing.CommandPolicy) *CommandInfoResolver {
126126
return &CommandInfoResolver{
127127
resolve: resolver,
128128
}
129129
}
130130

131131
func NewDefaultCommandPolicyResolver() *CommandInfoResolver {
132-
return NewCommandInfoResolver(func(ctx context.Context, cmdName string) *routing.CommandPolicy {
132+
return NewCommandInfoResolver(func(ctx context.Context, cmd Cmder) *routing.CommandPolicy {
133133
module := "core"
134-
command := cmdName
135-
cmdParts := strings.Split(cmdName, ".")
134+
command := cmd.Name()
135+
cmdParts := strings.Split(command, ".")
136136
if len(cmdParts) == 2 {
137137
module = cmdParts[0]
138138
command = cmdParts[1]
@@ -146,18 +146,18 @@ func NewDefaultCommandPolicyResolver() *CommandInfoResolver {
146146
})
147147
}
148148

149-
func (r *CommandInfoResolver) GetCommandPolicy(ctx context.Context, cmdName string) *routing.CommandPolicy {
149+
func (r *CommandInfoResolver) GetCommandPolicy(ctx context.Context, cmd Cmder) *routing.CommandPolicy {
150150
if r.resolve == nil {
151151
return nil
152152
}
153153

154-
policy := r.resolve(ctx, cmdName)
154+
policy := r.resolve(ctx, cmd)
155155
if policy != nil {
156156
return policy
157157
}
158158

159159
if r.fallBackResolver != nil {
160-
return r.fallBackResolver.GetCommandPolicy(ctx, cmdName)
160+
return r.fallBackResolver.GetCommandPolicy(ctx, cmd)
161161
}
162162

163163
return nil

osscluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
13401340

13411341
if c.opt.ReadOnly && c.cmdsAreReadOnly(ctx, cmds) {
13421342
for _, cmd := range cmds {
1343-
policy := c.extractCommandInfo(ctx, cmd.Name())
1343+
policy := c.extractCommandInfo(ctx, cmd)
13441344
if policy != nil && !policy.CanBeUsedInPipeline() {
13451345
return fmt.Errorf(
13461346
"redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(),
@@ -1357,7 +1357,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
13571357
}
13581358

13591359
for _, cmd := range cmds {
1360-
policy := c.extractCommandInfo(ctx, cmd.Name())
1360+
policy := c.extractCommandInfo(ctx, cmd)
13611361
if policy != nil && !policy.CanBeUsedInPipeline() {
13621362
return fmt.Errorf(
13631363
"redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(),
@@ -1991,8 +1991,8 @@ func (c *ClusterClient) SetCommandInfoResolver(cmdInfoResolver *CommandInfoResol
19911991
}
19921992

19931993
// extractCommandInfo retrieves the routing policy for a command
1994-
func (c *ClusterClient) extractCommandInfo(ctx context.Context, cmdName string) *routing.CommandPolicy {
1995-
if cmdInfo := c.cmdInfo(ctx, cmdName); cmdInfo != nil && cmdInfo.CommandPolicy != nil {
1994+
func (c *ClusterClient) extractCommandInfo(ctx context.Context, cmd Cmder) *routing.CommandPolicy {
1995+
if cmdInfo := c.cmdInfo(ctx, cmd.Name()); cmdInfo != nil && cmdInfo.CommandPolicy != nil {
19961996
return cmdInfo.CommandPolicy
19971997
}
19981998

osscluster_router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type slotResult struct {
2121

2222
// routeAndRun routes a command to the appropriate cluster nodes and executes it
2323
func (c *ClusterClient) routeAndRun(ctx context.Context, cmd Cmder, node *clusterNode) error {
24-
policy := c.cmdInfoResolver.GetCommandPolicy(ctx, cmd.Name())
24+
policy := c.cmdInfoResolver.GetCommandPolicy(ctx, cmd)
2525
if policy == nil {
2626
return c.executeDefault(ctx, cmd, node)
2727
}

0 commit comments

Comments
 (0)