From 9e97af3299bcc9f9903d8ef8a38f042a32cfa783 Mon Sep 17 00:00:00 2001 From: Zakaf <3315213+zakaf@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:53:27 +0900 Subject: [PATCH] make initialize to loop through replica nodes per cluster slots row --- redis/cluster.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/redis/cluster.py b/redis/cluster.py index cba62de077..c6ff9ba245 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -1549,25 +1549,25 @@ def initialize(self): # add this node to the nodes cache tmp_nodes_cache[target_node.name] = target_node + target_replica_nodes = [] + for replica_node in slot[3:]: + host = str_if_bytes(replica_node[0]) + port = int(replica_node[1]) + host, port = self.remap_host_port(host, port) + + target_replica_node = self._get_or_create_cluster_node( + host, port, REPLICA, tmp_nodes_cache + ) + target_replica_nodes.append(target_replica_node) + # add this node to the nodes cache + tmp_nodes_cache[target_replica_node.name] = target_replica_node + for i in range(int(slot[0]), int(slot[1]) + 1): if i not in tmp_slots: tmp_slots[i] = [] tmp_slots[i].append(target_node) - replica_nodes = [slot[j] for j in range(3, len(slot))] - - for replica_node in replica_nodes: - host = str_if_bytes(replica_node[0]) - port = replica_node[1] - host, port = self.remap_host_port(host, port) - - target_replica_node = self._get_or_create_cluster_node( - host, port, REPLICA, tmp_nodes_cache - ) + for target_replica_node in target_replica_nodes: tmp_slots[i].append(target_replica_node) - # add this node to the nodes cache - tmp_nodes_cache[ - target_replica_node.name - ] = target_replica_node else: # Validate that 2 nodes want to use the same slot cache # setup