summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvora-h <67596500+dvora-h@users.noreply.github.com>2022-03-14 13:43:05 +0200
committerGitHub <noreply@github.com>2022-03-14 13:43:05 +0200
commit9376ed82cd8b8296f5585eb96d137e54b56d723d (patch)
tree8579dd80f033f2f7fb30fa2585cd191a7ec2888d
parent8d949a3f39bc6fe17ee90009e78f17b32f69899a (diff)
downloadredis-py-9376ed82cd8b8296f5585eb96d137e54b56d723d.tar.gz
Add support for CLUSTER ADDSLOTSRANGE (#2017)
* add cluster addslotsrange * Add support for CLUSTER ADDSLOTSRANGE * docstring * fix test * skip test * linters
-rwxr-xr-xredis/client.py1
-rw-r--r--redis/cluster.py1
-rw-r--r--redis/commands/cluster.py16
-rw-r--r--tests/test_cluster.py6
4 files changed, 24 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index b12ad57..465bb5f 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 8c2dfc2..b6e2ab2 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 e14b6e3..3d42317 100644
--- a/redis/commands/cluster.py
+++ b/redis/commands/cluster.py
@@ -248,6 +248,22 @@ class RedisClusterCommands(
"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 ab98ed5..aa28b2a 100644
--- a/tests/test_cluster.py
+++ b/tests/test_cluster.py
@@ -853,6 +853,12 @@ class TestClusterRedisCommands:
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)