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

Method GetByName

ring.go:472–486  ·  view source on GitHub ↗
(shardName string)

Source from the content-addressed store, hash-verified

470}
471
472func (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
488func (c *ringSharding) Random() (*ringShard, error) {
489 return c.GetByKey(strconv.Itoa(rand.Int()))

Callers 2

ShardByNameMethod · 0.80

Calls 1

RandomMethod · 0.95

Tested by 1

ShardByNameMethod · 0.64