1
0
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:
fukua95
2025-06-09 16:06:21 +08:00
committed by GitHub
parent 858ecda7fd
commit 0f40ae3ff2

View File

@ -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) {