(shardName string)
| 470 | } |
| 471 | |
| 472 | func (c *ringSharding) GetByName(shardName string) (*ringShard, error) { |
| 473 | if shardName == "" { |
| 474 | return c.Random() |
| 475 | } |
| 476 | |
| 477 | c.mu.RLock() |
| 478 | defer c.mu.RUnlock() |
| 479 | |
| 480 | shard, ok := c.shards.m[shardName] |
| 481 | if !ok { |
| 482 | return nil, errors.New("redis: the shard is not in the ring") |
| 483 | } |
| 484 | |
| 485 | return shard, nil |
| 486 | } |
| 487 | |
| 488 | func (c *ringSharding) Random() (*ringShard, error) { |
| 489 | return c.GetByKey(strconv.Itoa(rand.Int())) |