diff options
author | Bar Shaul <88437685+barshaul@users.noreply.github.com> | 2022-06-23 19:28:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-23 19:28:02 +0300 |
commit | 63cf7ec5cbaca533b7607196dbf993917a65c0f9 (patch) | |
tree | fd02285634cdd1d7978e5c521edf89b201bb94a0 /redis/cluster.py | |
parent | d3a7a75c7b106e0864b3927c0904058e25c99958 (diff) | |
download | redis-py-63cf7ec5cbaca533b7607196dbf993917a65c0f9.tar.gz |
Added dynamic_startup_nodes configuration to RedisCluster. (#2244)
* Added dynamic_startup_nodes configuration to RedisCluster. By default, uses only the initial passed startup nodes to refresh the cluster topology. If set to true, sets the startup nodes to all of the discovered nodes.
* Added RedisCluster specific options to the README file and updated CHANGES
* Fixed timeout_error_topology_refresh test
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Diffstat (limited to 'redis/cluster.py')
-rw-r--r-- | redis/cluster.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/redis/cluster.py b/redis/cluster.py index 1737ec7..c5b6c8d 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -482,6 +482,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands): require_full_coverage=False, reinitialize_steps=10, read_from_replicas=False, + dynamic_startup_nodes=False, url=None, **kwargs, ): @@ -509,6 +510,14 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands): stale data. When set to true, read commands will be assigned between the primary and its replications in a Round-Robin manner. + :dynamic_startup_nodes: 'bool' + Set the RedisCluster's startup nodes to all of the discovered nodes. + If true, the cluster's discovered nodes will be used to determine the + cluster nodes-slots mapping in the next topology refresh. + It will remove the initial passed startup nodes if their endpoints aren't + listed in the CLUSTER SLOTS output. + If you use dynamic DNS endpoints for startup nodes but CLUSTER SLOTS lists + specific IP addresses, keep it at false. :cluster_error_retry_attempts: 'int' Retry command execution attempts when encountering ClusterDownError or ConnectionError @@ -598,6 +607,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands): startup_nodes=startup_nodes, from_url=from_url, require_full_coverage=require_full_coverage, + dynamic_startup_nodes=dynamic_startup_nodes, **kwargs, ) @@ -1283,6 +1293,7 @@ class NodesManager: from_url=False, require_full_coverage=False, lock=None, + dynamic_startup_nodes=False, **kwargs, ): self.nodes_cache = {} @@ -1292,6 +1303,7 @@ class NodesManager: self.populate_startup_nodes(startup_nodes) self.from_url = from_url self._require_full_coverage = require_full_coverage + self._dynamic_startup_nodes = dynamic_startup_nodes self._moved_exception = None self.connection_kwargs = kwargs self.read_load_balancer = LoadBalancer() @@ -1612,8 +1624,9 @@ class NodesManager: self.slots_cache = tmp_slots # Set the default node self.default_node = self.get_nodes_by_server_type(PRIMARY)[0] - # Populate the startup nodes with all discovered nodes - self.startup_nodes = tmp_nodes_cache + if self._dynamic_startup_nodes: + # Populate the startup nodes with all discovered nodes + self.startup_nodes = tmp_nodes_cache # If initialize was called after a MovedError, clear it self._moved_exception = None |