MCPcopy
hub / github.com/redis/go-redis / cmdNodeWithShardPicker

Method cmdNodeWithShardPicker

osscluster.go:2408–2436  ·  view source on GitHub ↗
(
	ctx context.Context,
	cmdName string,
	slot int,
	shardPicker routing.ShardPicker,
)

Source from the content-addressed store, hash-verified

2406}
2407
2408func (c *ClusterClient) cmdNodeWithShardPicker(
2409 ctx context.Context,
2410 cmdName string,
2411 slot int,
2412 shardPicker routing.ShardPicker,
2413) (*clusterNode, error) {
2414 state, err := c.state.Get(ctx)
2415 if err != nil {
2416 return nil, err
2417 }
2418
2419 // For keyless commands (slot == -1), use ShardPicker to select a shard
2420 // This respects the user's configured ShardPicker policy
2421 if slot == -1 {
2422 if len(state.Masters) == 0 {
2423 return nil, errClusterNoNodes
2424 }
2425 idx := shardPicker.Next(len(state.Masters))
2426 return state.Masters[idx], nil
2427 }
2428
2429 if c.opt.ReadOnly {
2430 cmdInfo := c.cmdInfo(ctx, cmdName)
2431 if cmdInfo != nil && cmdInfo.ReadOnly {
2432 return c.slotReadOnlyNode(state, slot)
2433 }
2434 }
2435 return state.slotMasterNode(slot)
2436}
2437
2438func (c *ClusterClient) slotReadOnlyNode(state *clusterState, slot int) (*clusterNode, error) {
2439 if c.opt.RouteByLatency {

Callers 3

processMethod · 0.95
executeMultiSlotMethod · 0.95
executeCursorCommandMethod · 0.95

Calls 5

cmdInfoMethod · 0.95
slotReadOnlyNodeMethod · 0.95
GetMethod · 0.65
NextMethod · 0.65
slotMasterNodeMethod · 0.45

Tested by

no test coverage detected