Skip to content

Commit 852839f

Browse files
committed
[GROW-2938] prevent get_node_from_slot from failing due to concurrent cluster slots refresh
1 parent 761fdec commit 852839f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

redis/cluster.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,10 @@ def get_node_from_slot(self, slot, read_from_replicas=False, server_type=None):
13961396
# randomly choose one of the replicas
13971397
node_idx = random.randint(1, len(self.slots_cache[slot]) - 1)
13981398

1399-
return self.slots_cache[slot][node_idx]
1399+
try:
1400+
return self.slots_cache[slot][node_idx]
1401+
except IndexError:
1402+
return self.slots_cache[slot][0]
14001403

14011404
def get_nodes_by_server_type(self, server_type):
14021405
"""

0 commit comments

Comments
 (0)