Skip to content

Commit

Permalink
Add support for CLUSTER ADDSLOTSRANGE (#2017)
Browse files Browse the repository at this point in the history
* add cluster addslotsrange

* Add support for CLUSTER ADDSLOTSRANGE

* docstring

* fix test

* skip test

* linters
  • Loading branch information
dvora-h committed Mar 14, 2022
1 parent 8d949a3 commit 9376ed8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
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 @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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

0 comments on commit 9376ed8

Please sign in to comment.