mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
fix: check if the shard exists to avoid returning nil (#3396)
Signed-off-by: fukua95 <fukua95@gmail.com>
This commit is contained in:
7
ring.go
7
ring.go
@ -405,7 +405,12 @@ func (c *ringSharding) GetByName(shardName string) (*ringShard, error) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
return c.shards.m[shardName], nil
|
||||
shard, ok := c.shards.m[shardName]
|
||||
if !ok {
|
||||
return nil, errors.New("redis: the shard is not in the ring")
|
||||
}
|
||||
|
||||
return shard, nil
|
||||
}
|
||||
|
||||
func (c *ringSharding) Random() (*ringShard, error) {
|
||||
|
Reference in New Issue
Block a user