diff --git a/redis/commands/cluster.py b/redis/commands/cluster.py index 7342c0c482..8f88590c1f 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -398,6 +398,18 @@ def cluster_slots(self, target_nodes=None): """ return self.execute_command("CLUSTER SLOTS", target_nodes=target_nodes) + def cluster_links(self, target_node): + """ + Each node in a Redis Cluster maintains a pair of long-lived TCP link with each + peer in the cluster: One for sending outbound messages towards the peer and one + for receiving inbound messages from the peer. + + This command outputs information of all such peer links as an array. + + For more information check https://redis.io/commands/cluster-links + """ + return self.execute_command("CLUSTER LINKS", target_nodes=target_node) + def readonly(self, target_nodes=None): """ Enables read queries. diff --git a/tests/test_cluster.py b/tests/test_cluster.py index ab98ed515d..0fa422d9f8 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1016,6 +1016,17 @@ def test_cluster_replicas(self, r): == "r4xfga22229cf3c652b6fca0d09ff69f3e0d4d" ) + @skip_if_server_version_lt("7.0.0") + def test_cluster_links(self, r): + node = r.get_random_node() + res = r.cluster_links(node) + links_to = sum(x.count("to") for x in res) + links_for = sum(x.count("from") for x in res) + assert links_to == links_for + print(res) + for i in range(0, len(res) - 1, 2): + assert res[i][3] == res[i + 1][3] + def test_readonly(self): r = get_mocked_redis_client(host=default_host, port=default_port) mock_all_nodes_resp(r, "OK")