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 ADDSLOTSRANGE #2017

Merged
merged 6 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 @@ -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,
Expand Down
1 change: 1 addition & 0 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down