Skip to content

Commit 0a5e486

Browse files
authored
Add support for CLUSTER MYID (#2063)
Co-authored-by: enjoy-binbin <[email protected]>
1 parent 9cfcaa4 commit 0a5e486

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

redis/commands/cluster.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ class RedisClusterCommands(
275275
r.cluster_info(target_nodes=RedisCluster.ALL_NODES)
276276
"""
277277

278+
def cluster_myid(self, target_node):
279+
"""
280+
Returns the node’s id.
281+
282+
:target_node: 'ClusterNode'
283+
The node to execute the command on
284+
285+
For more information check https://redis.io/commands/cluster-myid/
286+
"""
287+
return self.execute_command("CLUSTER MYID", target_nodes=target_node)
288+
278289
def cluster_addslots(self, target_node, *slots):
279290
"""
280291
Assign new hash slots to receiving node. Sends to specified node.

tests/test_cluster.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ def test_cluster_pubsub_numsub(self, r):
840840
channels = [(b"foo", 1), (b"bar", 2), (b"baz", 3)]
841841
assert r.pubsub_numsub("foo", "bar", "baz", target_nodes="all") == channels
842842

843+
def test_cluster_myid(self, r):
844+
node = r.get_random_node()
845+
myid = r.cluster_myid(node)
846+
assert len(myid) == 40
847+
843848
def test_cluster_slots(self, r):
844849
mock_all_nodes_resp(r, default_cluster_slots)
845850
cluster_slots = r.cluster_slots()

0 commit comments

Comments
 (0)