From 9376ed82cd8b8296f5585eb96d137e54b56d723d Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Mon, 14 Mar 2022 13:43:05 +0200 Subject: [PATCH] Add support for CLUSTER ADDSLOTSRANGE (#2017) * add cluster addslotsrange * Add support for CLUSTER ADDSLOTSRANGE * docstring * fix test * skip test * linters --- redis/client.py | 1 + redis/cluster.py | 1 + redis/commands/cluster.py | 16 ++++++++++++++++ tests/test_cluster.py | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/redis/client.py b/redis/client.py index b12ad578d6..465bb5f2fd 100755 --- a/redis/client.py +++ b/redis/client.py @@ -710,6 +710,7 @@ class AbstractRedis: "CLIENT GETREDIR": int, "CLIENT TRACKINGINFO": lambda r: list(map(str_if_bytes, r)), "CLUSTER ADDSLOTS": bool_ok, + "CLUSTER ADDSLOTSRANGE": bool_ok, "CLUSTER COUNT-FAILURE-REPORTS": lambda x: int(x), "CLUSTER COUNTKEYSINSLOT": lambda x: int(x), "CLUSTER DELSLOTS": bool_ok, diff --git a/redis/cluster.py b/redis/cluster.py index 8c2dfc271b..b6e2ab2581 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -320,6 +320,7 @@ class RedisCluster(RedisClusterCommands): CLUSTER_COMMANDS_RESPONSE_CALLBACKS = { "CLUSTER ADDSLOTS": bool, + "CLUSTER ADDSLOTSRANGE": bool, "CLUSTER COUNT-FAILURE-REPORTS": int, "CLUSTER COUNTKEYSINSLOT": int, "CLUSTER DELSLOTS": bool, diff --git a/redis/commands/cluster.py b/redis/commands/cluster.py index e14b6e35ee..3d42317e2d 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -248,6 +248,22 @@ def cluster_addslots(self, target_node, *slots): "CLUSTER ADDSLOTS", *slots, target_nodes=target_node ) + def cluster_addslotsrange(self, target_node, *slots): + """ + Similar to the CLUSTER ADDSLOTS command. + The difference between the two commands is that ADDSLOTS takes a list of slots + to assign to the node, while ADDSLOTSRANGE takes a list of slot ranges + (specified by start and end slots) to assign to the node. + + :target_node: 'ClusterNode' + The node to execute the command on + + For more information check https://redis.io/commands/cluster-addslotsrange + """ + return self.execute_command( + "CLUSTER ADDSLOTSRANGE", *slots, target_nodes=target_node + ) + def cluster_countkeysinslot(self, slot_id): """ Return the number of local keys in the specified hash slot diff --git a/tests/test_cluster.py b/tests/test_cluster.py index ab98ed515d..aa28b2a555 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -853,6 +853,12 @@ def test_cluster_addslots(self, r): mock_node_resp(node, "OK") assert r.cluster_addslots(node, 1, 2, 3) is True + @skip_if_server_version_lt("7.0.0") + def test_cluster_addslotsrange(self, r): + node = r.get_random_node() + mock_node_resp(node, "OK") + assert r.cluster_addslotsrange(node, 1, 5) + def test_cluster_countkeysinslot(self, r): node = r.nodes_manager.get_node_from_slot(1) mock_node_resp(node, 2)