@@ -139,6 +139,14 @@ class ValkeyCluster(AbstractValkey, AbstractValkeyCluster, AsyncValkeyClusterCom
139
139
| Enable read from replicas in READONLY mode. You can read possibly stale data.
140
140
When set to true, read commands will be assigned between the primary and
141
141
its replications in a Round-Robin manner.
142
+ :param dynamic_startup_nodes:
143
+ | Set the ValkeyCluster's startup nodes to all the discovered nodes.
144
+ If true (default value), the cluster's discovered nodes will be used to
145
+ determine the cluster nodes-slots mapping in the next topology refresh.
146
+ It will remove the initial passed startup nodes if their endpoints aren't
147
+ listed in the CLUSTER SLOTS output.
148
+ If you use dynamic DNS endpoints for startup nodes but CLUSTER SLOTS lists
149
+ specific IP addresses, it is best to set it to false.
142
150
:param reinitialize_steps:
143
151
| Specifies the number of MOVED errors that need to occur before reinitializing
144
152
the whole cluster topology. If a MOVED error occurs and the cluster does not
@@ -237,6 +245,7 @@ def __init__(
237
245
startup_nodes : Optional [List ["ClusterNode" ]] = None ,
238
246
require_full_coverage : bool = True ,
239
247
read_from_replicas : bool = False ,
248
+ dynamic_startup_nodes : bool = True ,
240
249
reinitialize_steps : int = 5 ,
241
250
cluster_error_retry_attempts : int = 3 ,
242
251
connection_error_retry_attempts : int = 3 ,
@@ -389,6 +398,7 @@ def __init__(
389
398
startup_nodes ,
390
399
require_full_coverage ,
391
400
kwargs ,
401
+ dynamic_startup_nodes = dynamic_startup_nodes ,
392
402
address_remap = address_remap ,
393
403
)
394
404
self .encoder = Encoder (encoding , encoding_errors , decode_responses )
@@ -1142,6 +1152,7 @@ class NodesManager:
1142
1152
"require_full_coverage" ,
1143
1153
"slots_cache" ,
1144
1154
"startup_nodes" ,
1155
+ "_dynamic_startup_nodes" ,
1145
1156
"address_remap" ,
1146
1157
)
1147
1158
@@ -1150,11 +1161,13 @@ def __init__(
1150
1161
startup_nodes : List ["ClusterNode" ],
1151
1162
require_full_coverage : bool ,
1152
1163
connection_kwargs : Dict [str , Any ],
1164
+ dynamic_startup_nodes : bool = True ,
1153
1165
address_remap : Optional [Callable [[Tuple [str , int ]], Tuple [str , int ]]] = None ,
1154
1166
) -> None :
1155
1167
self .startup_nodes = {node .name : node for node in startup_nodes }
1156
1168
self .require_full_coverage = require_full_coverage
1157
1169
self .connection_kwargs = connection_kwargs
1170
+ self ._dynamic_startup_nodes = dynamic_startup_nodes
1158
1171
self .address_remap = address_remap
1159
1172
1160
1173
self .default_node : "ClusterNode" = None
@@ -1387,8 +1400,10 @@ async def initialize(self) -> None:
1387
1400
# Set the tmp variables to the real variables
1388
1401
self .slots_cache = tmp_slots
1389
1402
self .set_nodes (self .nodes_cache , tmp_nodes_cache , remove_old = True )
1390
- # Populate the startup nodes with all discovered nodes
1391
- self .set_nodes (self .startup_nodes , self .nodes_cache , remove_old = True )
1403
+
1404
+ if self ._dynamic_startup_nodes :
1405
+ # Populate the startup nodes with all discovered nodes
1406
+ self .set_nodes (self .startup_nodes , self .nodes_cache , remove_old = True )
1392
1407
1393
1408
# Set the default node
1394
1409
self .default_node = self .get_nodes_by_server_type (PRIMARY )[0 ]
0 commit comments