Skip to content

Commit 9376ed8

Browse files
authored
Add support for CLUSTER ADDSLOTSRANGE (#2017)
* add cluster addslotsrange * Add support for CLUSTER ADDSLOTSRANGE * docstring * fix test * skip test * linters
1 parent 8d949a3 commit 9376ed8

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

redis/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ class AbstractRedis:
710710
"CLIENT GETREDIR": int,
711711
"CLIENT TRACKINGINFO": lambda r: list(map(str_if_bytes, r)),
712712
"CLUSTER ADDSLOTS": bool_ok,
713+
"CLUSTER ADDSLOTSRANGE": bool_ok,
713714
"CLUSTER COUNT-FAILURE-REPORTS": lambda x: int(x),
714715
"CLUSTER COUNTKEYSINSLOT": lambda x: int(x),
715716
"CLUSTER DELSLOTS": bool_ok,

redis/cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ class RedisCluster(RedisClusterCommands):
320320

321321
CLUSTER_COMMANDS_RESPONSE_CALLBACKS = {
322322
"CLUSTER ADDSLOTS": bool,
323+
"CLUSTER ADDSLOTSRANGE": bool,
323324
"CLUSTER COUNT-FAILURE-REPORTS": int,
324325
"CLUSTER COUNTKEYSINSLOT": int,
325326
"CLUSTER DELSLOTS": bool,

redis/commands/cluster.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ def cluster_addslots(self, target_node, *slots):
248248
"CLUSTER ADDSLOTS", *slots, target_nodes=target_node
249249
)
250250

251+
def cluster_addslotsrange(self, target_node, *slots):
252+
"""
253+
Similar to the CLUSTER ADDSLOTS command.
254+
The difference between the two commands is that ADDSLOTS takes a list of slots
255+
to assign to the node, while ADDSLOTSRANGE takes a list of slot ranges
256+
(specified by start and end slots) to assign to the node.
257+
258+
:target_node: 'ClusterNode'
259+
The node to execute the command on
260+
261+
For more information check https://redis.io/commands/cluster-addslotsrange
262+
"""
263+
return self.execute_command(
264+
"CLUSTER ADDSLOTSRANGE", *slots, target_nodes=target_node
265+
)
266+
251267
def cluster_countkeysinslot(self, slot_id):
252268
"""
253269
Return the number of local keys in the specified hash slot

tests/test_cluster.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ def test_cluster_addslots(self, r):
853853
mock_node_resp(node, "OK")
854854
assert r.cluster_addslots(node, 1, 2, 3) is True
855855

856+
@skip_if_server_version_lt("7.0.0")
857+
def test_cluster_addslotsrange(self, r):
858+
node = r.get_random_node()
859+
mock_node_resp(node, "OK")
860+
assert r.cluster_addslotsrange(node, 1, 5)
861+
856862
def test_cluster_countkeysinslot(self, r):
857863
node = r.nodes_manager.get_node_from_slot(1)
858864
mock_node_resp(node, 2)

0 commit comments

Comments
 (0)