Skip to content

Commit 5d5f892

Browse files
authored
Add support for CLUSTER DELSLOTSRANGE (#2018)
* delslotsrange * test * linters * skip test * linters
1 parent 9376ed8 commit 5d5f892

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

redis/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ class AbstractRedis:
714714
"CLUSTER COUNT-FAILURE-REPORTS": lambda x: int(x),
715715
"CLUSTER COUNTKEYSINSLOT": lambda x: int(x),
716716
"CLUSTER DELSLOTS": bool_ok,
717+
"CLUSTER DELSLOTSRANGE": bool_ok,
717718
"CLUSTER FAILOVER": bool_ok,
718719
"CLUSTER FORGET": bool_ok,
719720
"CLUSTER INFO": parse_cluster_info,

redis/cluster.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class RedisCluster(RedisClusterCommands):
311311
[
312312
"CLUSTER COUNTKEYSINSLOT",
313313
"CLUSTER DELSLOTS",
314+
"CLUSTER DELSLOTSRANGE",
314315
"CLUSTER GETKEYSINSLOT",
315316
"CLUSTER SETSLOT",
316317
],
@@ -324,6 +325,7 @@ class RedisCluster(RedisClusterCommands):
324325
"CLUSTER COUNT-FAILURE-REPORTS": int,
325326
"CLUSTER COUNTKEYSINSLOT": int,
326327
"CLUSTER DELSLOTS": bool,
328+
"CLUSTER DELSLOTSRANGE": bool,
327329
"CLUSTER FAILOVER": bool,
328330
"CLUSTER FORGET": bool,
329331
"CLUSTER GETKEYSINSLOT": list,

redis/commands/cluster.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ def cluster_delslots(self, *slots):
287287
"""
288288
return [self.execute_command("CLUSTER DELSLOTS", slot) for slot in slots]
289289

290+
def cluster_delslotsrange(self, *slots):
291+
"""
292+
Similar to the CLUSTER DELSLOTS command.
293+
The difference is that CLUSTER DELSLOTS takes a list of hash slots to remove
294+
from the node, while CLUSTER DELSLOTSRANGE takes a list of slot ranges to remove
295+
from the node.
296+
297+
For more information check https://redis.io/commands/cluster-delslotsrange
298+
"""
299+
return self.execute_command("CLUSTER DELSLOTSRANGE", *slots)
300+
290301
def cluster_failover(self, target_node, option=None):
291302
"""
292303
Forces a slave to perform a manual failover of its master

tests/test_cluster.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,13 @@ def test_cluster_delslots(self):
891891
assert node0.redis_connection.connection.read_response.called
892892
assert node1.redis_connection.connection.read_response.called
893893

894+
@skip_if_server_version_lt("7.0.0")
895+
def test_cluster_delslotsrange(self, r):
896+
node = r.get_random_node()
897+
mock_node_resp(node, "OK")
898+
r.cluster_addslots(node, 1, 2, 3, 4, 5)
899+
assert r.cluster_delslotsrange(1, 5)
900+
894901
def test_cluster_failover(self, r):
895902
node = r.get_random_node()
896903
mock_node_resp(node, "OK")

0 commit comments

Comments
 (0)