Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CLUSTER DELSLOTSRANGE #2018

Merged
merged 5 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ class AbstractRedis:
"CLUSTER COUNT-FAILURE-REPORTS": lambda x: int(x),
"CLUSTER COUNTKEYSINSLOT": lambda x: int(x),
"CLUSTER DELSLOTS": bool_ok,
"CLUSTER DELSLOTSRANGE": bool_ok,
"CLUSTER FAILOVER": bool_ok,
"CLUSTER FORGET": bool_ok,
"CLUSTER INFO": parse_cluster_info,
Expand Down
2 changes: 2 additions & 0 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class RedisCluster(RedisClusterCommands):
[
"CLUSTER COUNTKEYSINSLOT",
"CLUSTER DELSLOTS",
"CLUSTER DELSLOTSRANGE",
"CLUSTER GETKEYSINSLOT",
"CLUSTER SETSLOT",
],
Expand All @@ -311,6 +312,7 @@ class RedisCluster(RedisClusterCommands):
"CLUSTER COUNT-FAILURE-REPORTS": int,
"CLUSTER COUNTKEYSINSLOT": int,
"CLUSTER DELSLOTS": bool,
"CLUSTER DELSLOTSRANGE": bool,
"CLUSTER FAILOVER": bool,
"CLUSTER FORGET": bool,
"CLUSTER GETKEYSINSLOT": list,
Expand Down
11 changes: 11 additions & 0 deletions redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ def cluster_delslots(self, *slots):
"""
return [self.execute_command("CLUSTER DELSLOTS", slot) for slot in slots]

def cluster_delslotsrange(self, *slots):
"""
Similar to the CLUSTER DELSLOTS command.
The difference is that CLUSTER DELSLOTS takes a list of hash slots to remove
from the node, while CLUSTER DELSLOTSRANGE takes a list of slot ranges to remove
from the node.

For more information check https://redis.io/commands/cluster-delslotsrange
"""
return self.execute_command("CLUSTER DELSLOTSRANGE", *slots)

def cluster_failover(self, target_node, option=None):
"""
Forces a slave to perform a manual failover of its master
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ def test_cluster_delslots(self):
assert node0.redis_connection.connection.read_response.called
assert node1.redis_connection.connection.read_response.called

@skip_if_server_version_lt("7.0.0")
def test_cluster_delslotsrange(self, r):
node = r.get_random_node()
mock_node_resp(node, "OK")
r.cluster_addslots(node, 1, 2, 3, 4, 5)
assert r.cluster_delslotsrange(1, 5)

def test_cluster_failover(self, r):
node = r.get_random_node()
mock_node_resp(node, "OK")
Expand Down