diff options
Diffstat (limited to 'redis/cluster.py')
-rw-r--r-- | redis/cluster.py | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/redis/cluster.py b/redis/cluster.py index eead2b4..c5634a0 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -414,14 +414,25 @@ class RedisCluster(RedisClusterCommands): stale data. When set to true, read commands will be assigned between the primary and its replications in a Round-Robin manner. - :cluster_error_retry_attempts: 'int' + :cluster_error_retry_attempts: 'int' Retry command execution attempts when encountering ClusterDownError or ConnectionError - :retry_on_timeout: 'bool' + :retry_on_timeout: 'bool' To specify a retry policy, first set `retry_on_timeout` to `True` then set `retry` to a valid `Retry` object - :retry: 'Retry' + :retry: 'Retry' a `Retry` object + :reinitialize_steps: 'int' + Specifies the number of MOVED errors that need to occur before + reinitializing the whole cluster topology. If a MOVED error occurs + and the cluster does not need to be reinitialized on this current + error handling, only the MOVED slot will be patched with the + redirected node. + To reinitialize the cluster on every MOVED error, set + reinitialize_steps to 1. + To avoid reinitializing the cluster on moved errors, set + reinitialize_steps to 0. + :**kwargs: Extra arguments that will be sent into Redis instance when created (See Official redis-py doc for supported kwargs @@ -727,7 +738,9 @@ class RedisCluster(RedisClusterCommands): return [node] def _should_reinitialized(self): - # In order not to reinitialize the cluster, the user can set + # To reinitialize the cluster on every MOVED error, + # set reinitialize_steps to 1. + # To avoid reinitializing the cluster on moved errors, set # reinitialize_steps to 0. if self.reinitialize_steps == 0: return False @@ -958,8 +971,8 @@ class RedisCluster(RedisClusterCommands): # redirected node output and try again. If MovedError exceeds # 'reinitialize_steps' number of times, we will force # reinitializing the tables, and then try again. - # 'reinitialize_steps' counter will increase faster when the - # same client object is shared between multiple threads. To + # 'reinitialize_steps' counter will increase faster when + # the same client object is shared between multiple threads. To # reduce the frequency you can set this variable in the # RedisCluster constructor. log.exception("MovedError") @@ -1055,6 +1068,10 @@ class ClusterNode: def __eq__(self, obj): return isinstance(obj, ClusterNode) and obj.name == self.name + def __del__(self): + if self.redis_connection is not None: + self.redis_connection.close() + class LoadBalancer: """ @@ -1300,6 +1317,11 @@ class NodesManager: startup_node.host, startup_node.port, **copy_kwargs ) self.startup_nodes[startup_node.name].redis_connection = r + # Make sure cluster mode is enabled on this node + if bool(r.info().get("cluster_enabled")) is False: + raise RedisClusterException( + "Cluster mode is not enabled on this node" + ) cluster_slots = r.execute_command("CLUSTER SLOTS") startup_nodes_reachable = True except (ConnectionError, TimeoutError) as e: @@ -1327,7 +1349,7 @@ class NodesManager: message = e.__str__() raise RedisClusterException( 'ERROR sending "cluster slots" command to redis ' - f"server: {startup_node}. error: {message}" + f"server {startup_node.name}. error: {message}" ) # CLUSTER SLOTS command results in the following output: |