diff --git a/redis/client.py b/redis/client.py index 0eade79e90..592d35ef85 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 b8d6b1997f..3ff72bd8f3 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -308,6 +308,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 8bdcbbadf6..00f501adb3 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -244,6 +244,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)