Skip to content

Commit aaa212b

Browse files
committed
[GROW-2938] prevent get_node_from_slot from failing due to concurrent cluster slots refresh
1 parent 179e924 commit aaa212b

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
@@ -1414,7 +1414,10 @@ def get_node_from_slot(self, slot, read_from_replicas=False, server_type=None):
14141414
# randomly choose one of the replicas
14151415
node_idx = random.randint(1, len(self.slots_cache[slot]) - 1)
14161416

1417-
return self.slots_cache[slot][node_idx]
1417+
try:
1418+
return self.slots_cache[slot][node_idx]
1419+
except IndexError:
1420+
return self.slots_cache[slot][0]
14181421

14191422
def get_nodes_by_server_type(self, server_type):
14201423
"""

0 commit comments

Comments
 (0)