Skip to content

Commit 0f40ae3

Browse files
authored
fix: check if the shard exists to avoid returning nil (#3396)
Signed-off-by: fukua95 <[email protected]>
1 parent 858ecda commit 0f40ae3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ring.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,12 @@ func (c *ringSharding) GetByName(shardName string) (*ringShard, error) {
405405
c.mu.RLock()
406406
defer c.mu.RUnlock()
407407

408-
return c.shards.m[shardName], nil
408+
shard, ok := c.shards.m[shardName]
409+
if !ok {
410+
return nil, errors.New("redis: the shard is not in the ring")
411+
}
412+
413+
return shard, nil
409414
}
410415

411416
func (c *ringSharding) Random() (*ringShard, error) {

0 commit comments

Comments
 (0)