diff --git a/redis/commands/cluster.py b/redis/commands/cluster.py index bcbfbd599d..c3d7bd6e49 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -275,6 +275,17 @@ class RedisClusterCommands( r.cluster_info(target_nodes=RedisCluster.ALL_NODES) """ + def cluster_myid(self, target_node): + """ + Returns the node’s id. + + :target_node: 'ClusterNode' + The node to execute the command on + + For more information check https://redis.io/commands/cluster-myid/ + """ + return self.execute_command("CLUSTER MYID", target_nodes=target_node) + def cluster_addslots(self, target_node, *slots): """ Assign new hash slots to receiving node. Sends to specified node. diff --git a/tests/test_cluster.py b/tests/test_cluster.py index 70cbe4f9c4..ecc8624015 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -840,6 +840,11 @@ def test_cluster_pubsub_numsub(self, r): channels = [(b"foo", 1), (b"bar", 2), (b"baz", 3)] assert r.pubsub_numsub("foo", "bar", "baz", target_nodes="all") == channels + def test_cluster_myid(self, r): + node = r.get_random_node() + myid = r.cluster_myid(node) + assert len(myid) == 40 + def test_cluster_slots(self, r): mock_all_nodes_resp(r, default_cluster_slots) cluster_slots = r.cluster_slots()