( ctx context.Context, cmdName string, slot int, shardPicker routing.ShardPicker, )
| 2406 | } |
| 2407 | |
| 2408 | func (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 | |
| 2438 | func (c *ClusterClient) slotReadOnlyNode(state *clusterState, slot int) (*clusterNode, error) { |
| 2439 | if c.opt.RouteByLatency { |
no test coverage detected