Skip to content

Commit bdb6036

Browse files
change func signature from cmdName to cmder
1 parent 9c42243 commit bdb6036

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
@@ -1425,7 +1425,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
14251425

14261426
if c.opt.ReadOnly && c.cmdsAreReadOnly(ctx, cmds) {
14271427
for _, cmd := range cmds {
1428-
policy := c.extractCommandInfo(ctx, cmd.Name())
1428+
policy := c.extractCommandInfo(ctx, cmd)
14291429
if policy != nil && !policy.CanBeUsedInPipeline() {
14301430
return fmt.Errorf(
14311431
"redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(),
@@ -1442,7 +1442,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
14421442
}
14431443

14441444
for _, cmd := range cmds {
1445-
policy := c.extractCommandInfo(ctx, cmd.Name())
1445+
policy := c.extractCommandInfo(ctx, cmd)
14461446
if policy != nil && !policy.CanBeUsedInPipeline() {
14471447
return fmt.Errorf(
14481448
"redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(),
@@ -2208,8 +2208,8 @@ func (c *ClusterClient) SetCommandInfoResolver(cmdInfoResolver *CommandInfoResol
22082208
}
22092209

22102210
// extractCommandInfo retrieves the routing policy for a command
2211-
func (c *ClusterClient) extractCommandInfo(ctx context.Context, cmdName string) *routing.CommandPolicy {
2212-
if cmdInfo := c.cmdInfo(ctx, cmdName); cmdInfo != nil && cmdInfo.CommandPolicy != nil {
2211+
func (c *ClusterClient) extractCommandInfo(ctx context.Context, cmd Cmder) *routing.CommandPolicy {
2212+
if cmdInfo := c.cmdInfo(ctx, cmd.Name()); cmdInfo != nil && cmdInfo.CommandPolicy != nil {
22132213
return cmdInfo.CommandPolicy
22142214
}
22152215

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)