@@ -1317,37 +1317,35 @@ async def initialize(self) -> None:
1317
1317
port = int (primary_node [1 ])
1318
1318
host , port = self .remap_host_port (host , port )
1319
1319
1320
+ nodes_for_slot = []
1321
+
1320
1322
target_node = tmp_nodes_cache .get (get_node_name (host , port ))
1321
1323
if not target_node :
1322
1324
target_node = ClusterNode (
1323
1325
host , port , PRIMARY , ** self .connection_kwargs
1324
1326
)
1325
1327
# add this node to the nodes cache
1326
1328
tmp_nodes_cache [target_node .name ] = target_node
1329
+ nodes_for_slot .append (target_node )
1330
+
1331
+ replica_nodes = [slot [j ] for j in range (3 , len (slot ))]
1332
+ for replica_node in replica_nodes :
1333
+ host = replica_node [0 ]
1334
+ port = replica_node [1 ]
1335
+ host , port = self .remap_host_port (host , port )
1336
+
1337
+ target_replica_node = tmp_nodes_cache .get (get_node_name (host , port ))
1338
+ if not target_replica_node :
1339
+ target_replica_node = ClusterNode (
1340
+ host , port , REPLICA , ** self .connection_kwargs
1341
+ )
1342
+ nodes_for_slot .append (target_replica_node )
1343
+ # add this node to the nodes cache
1344
+ tmp_nodes_cache [target_replica_node .name ] = target_replica_node
1327
1345
1328
1346
for i in range (int (slot [0 ]), int (slot [1 ]) + 1 ):
1329
1347
if i not in tmp_slots :
1330
- tmp_slots [i ] = []
1331
- tmp_slots [i ].append (target_node )
1332
- replica_nodes = [slot [j ] for j in range (3 , len (slot ))]
1333
-
1334
- for replica_node in replica_nodes :
1335
- host = replica_node [0 ]
1336
- port = replica_node [1 ]
1337
- host , port = self .remap_host_port (host , port )
1338
-
1339
- target_replica_node = tmp_nodes_cache .get (
1340
- get_node_name (host , port )
1341
- )
1342
- if not target_replica_node :
1343
- target_replica_node = ClusterNode (
1344
- host , port , REPLICA , ** self .connection_kwargs
1345
- )
1346
- tmp_slots [i ].append (target_replica_node )
1347
- # add this node to the nodes cache
1348
- tmp_nodes_cache [target_replica_node .name ] = (
1349
- target_replica_node
1350
- )
1348
+ tmp_slots [i ] = nodes_for_slot
1351
1349
else :
1352
1350
# Validate that 2 nodes want to use the same slot cache
1353
1351
# setup
0 commit comments