@@ -996,9 +996,11 @@ def _execute_command(self, target_node, *args, **kwargs):
996
996
self .reinitialize_counter += 1
997
997
if self ._should_reinitialized ():
998
998
self .nodes_manager .initialize ()
999
+ # Reset the counter
1000
+ self .reinitialize_counter = 0
999
1001
else :
1000
1002
self .nodes_manager .update_moved_exception (e )
1001
- moved = True
1003
+ moved = True
1002
1004
except TryAgainError :
1003
1005
log .exception ("TryAgainError" )
1004
1006
@@ -1320,6 +1322,7 @@ def initialize(self):
1320
1322
tmp_slots = {}
1321
1323
disagreements = []
1322
1324
startup_nodes_reachable = False
1325
+ fully_covered = False
1323
1326
kwargs = self .connection_kwargs
1324
1327
for startup_node in self .startup_nodes .values ():
1325
1328
try :
@@ -1431,6 +1434,12 @@ def initialize(self):
1431
1434
f'slots cache: { ", " .join (disagreements )} '
1432
1435
)
1433
1436
1437
+ fully_covered = self .check_slots_coverage (tmp_slots )
1438
+ if fully_covered :
1439
+ # Don't need to continue to the next startup node if all
1440
+ # slots are covered
1441
+ break
1442
+
1434
1443
if not startup_nodes_reachable :
1435
1444
raise RedisClusterException (
1436
1445
"Redis Cluster cannot be connected. Please provide at least "
@@ -1440,7 +1449,6 @@ def initialize(self):
1440
1449
# Create Redis connections to all nodes
1441
1450
self .create_redis_connections (list (tmp_nodes_cache .values ()))
1442
1451
1443
- fully_covered = self .check_slots_coverage (tmp_slots )
1444
1452
# Check if the slots are not fully covered
1445
1453
if not fully_covered and self ._require_full_coverage :
1446
1454
# Despite the requirement that the slots be covered, there
@@ -1478,6 +1486,8 @@ def initialize(self):
1478
1486
self .default_node = self .get_nodes_by_server_type (PRIMARY )[0 ]
1479
1487
# Populate the startup nodes with all discovered nodes
1480
1488
self .populate_startup_nodes (self .nodes_cache .values ())
1489
+ # If initialize was called after a MovedError, clear it
1490
+ self ._moved_exception = None
1481
1491
1482
1492
def close (self ):
1483
1493
self .default_node = None
0 commit comments