diff --git a/bench_decode_test.go b/bench_decode_test.go index 50e33908..16bdf2cd 100644 --- a/bench_decode_test.go +++ b/bench_decode_test.go @@ -59,14 +59,6 @@ func NewClusterClientStub(resp []byte) *ClientStub { }, }) - // init command. - tmpClient := NewClient(&Options{Addr: ":6379"}) - cmdsInfo, err := tmpClient.Command(ctx).Result() - _ = tmpClient.Close() - client.cmdsInfoCache = newCmdsInfoCache(func(_ context.Context) (map[string]*CommandInfo, error) { - return cmdsInfo, err - }) - stub.Cmdable = client return stub } diff --git a/command.go b/command.go index 3dd475fa..1a33cb32 100644 --- a/command.go +++ b/command.go @@ -75,7 +75,7 @@ func writeCmd(wr *proto.Writer, cmd Cmder) error { return wr.WriteArgs(cmd.Args()) } -func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int { +func cmdFirstKeyPos(cmd Cmder) int { if pos := cmd.firstKeyPos(); pos != 0 { return int(pos) } @@ -95,10 +95,6 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int { return 2 } } - - if info != nil { - return int(info.FirstKeyPos) - } return 1 } diff --git a/osscluster.go b/osscluster.go index 93e0eef1..b8a82d9b 100644 --- a/osscluster.go +++ b/osscluster.go @@ -907,7 +907,6 @@ func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error { } func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error { - cmdInfo := c.cmdInfo(ctx, cmd.Name()) slot := c.cmdSlot(ctx, cmd) var node *clusterNode var ask bool @@ -921,7 +920,7 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error { if node == nil { var err error - node, err = c.cmdNode(ctx, cmdInfo, slot) + node, err = c.cmdNode(ctx, cmd.Name(), slot) if err != nil { return err } @@ -1783,8 +1782,7 @@ func (c *ClusterClient) cmdSlot(ctx context.Context, cmd Cmder) int { return args[2].(int) } - cmdInfo := c.cmdInfo(ctx, cmd.Name()) - return cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo)) + return cmdSlot(cmd, cmdFirstKeyPos(cmd)) } func cmdSlot(cmd Cmder, pos int) int { @@ -1797,7 +1795,7 @@ func cmdSlot(cmd Cmder, pos int) int { func (c *ClusterClient) cmdNode( ctx context.Context, - cmdInfo *CommandInfo, + cmdName string, slot int, ) (*clusterNode, error) { state, err := c.state.Get(ctx) @@ -1805,8 +1803,11 @@ func (c *ClusterClient) cmdNode( return nil, err } - if c.opt.ReadOnly && cmdInfo != nil && cmdInfo.ReadOnly { - return c.slotReadOnlyNode(state, slot) + if c.opt.ReadOnly { + cmdInfo := c.cmdInfo(ctx, cmdName) + if cmdInfo != nil && cmdInfo.ReadOnly { + return c.slotReadOnlyNode(state, slot) + } } return state.slotMasterNode(slot) } diff --git a/ring.go b/ring.go index 367a542e..0c031b5a 100644 --- a/ring.go +++ b/ring.go @@ -678,21 +678,8 @@ func (c *Ring) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, error) { return nil, firstErr } -func (c *Ring) cmdInfo(ctx context.Context, name string) *CommandInfo { - cmdsInfo, err := c.cmdsInfoCache.Get(ctx) - if err != nil { - return nil - } - info := cmdsInfo[name] - if info == nil { - internal.Logger.Printf(ctx, "info for cmd=%s not found", name) - } - return info -} - func (c *Ring) cmdShard(ctx context.Context, cmd Cmder) (*ringShard, error) { - cmdInfo := c.cmdInfo(ctx, cmd.Name()) - pos := cmdFirstKeyPos(cmd, cmdInfo) + pos := cmdFirstKeyPos(cmd) if pos == 0 { return c.sharding.Random() } @@ -760,8 +747,7 @@ func (c *Ring) generalProcessPipeline( cmdsMap := make(map[string][]Cmder) for _, cmd := range cmds { - cmdInfo := c.cmdInfo(ctx, cmd.Name()) - hash := cmd.stringArg(cmdFirstKeyPos(cmd, cmdInfo)) + hash := cmd.stringArg(cmdFirstKeyPos(cmd)) if hash != "" { hash = c.sharding.Hash(hash) }