From 11d18f62e5152a1c8b864bc47e8cba3c6fdbf6da Mon Sep 17 00:00:00 2001 From: dvora-h Date: Thu, 24 Feb 2022 13:26:46 +0200 Subject: [PATCH 1/3] cluster links --- redis/commands/cluster.py | 3 +++ tests/test_cluster.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/redis/commands/cluster.py b/redis/commands/cluster.py index 8bdcbbadf6..e120af58e4 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -396,6 +396,9 @@ def cluster_slots(self, target_nodes=None): """ return self.execute_command("CLUSTER SLOTS", target_nodes=target_nodes) + def cluster_links(self, target_node): + 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..d91e3cca1f 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1016,6 +1016,16 @@ def test_cluster_replicas(self, r): == "r4xfga22229cf3c652b6fca0d09ff69f3e0d4d" ) + def test_cluster_links(self, unstable_r): + node = unstable_r.get_random_node() + res = unstable_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") From 01a53ecdaa8315af6be73b41c65eecb287125697 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Thu, 24 Feb 2022 14:16:09 +0200 Subject: [PATCH 2/3] docstring --- redis/commands/cluster.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/redis/commands/cluster.py b/redis/commands/cluster.py index e120af58e4..a39a074a48 100644 --- a/redis/commands/cluster.py +++ b/redis/commands/cluster.py @@ -397,6 +397,15 @@ 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): From 0f8bd85774e1d90f5c5014c2a852226f62926fc8 Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Tue, 8 Mar 2022 02:30:10 +0200 Subject: [PATCH 3/3] skip test --- tests/test_cluster.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_cluster.py b/tests/test_cluster.py index d91e3cca1f..0fa422d9f8 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1016,9 +1016,10 @@ def test_cluster_replicas(self, r): == "r4xfga22229cf3c652b6fca0d09ff69f3e0d4d" ) - def test_cluster_links(self, unstable_r): - node = unstable_r.get_random_node() - res = unstable_r.cluster_links(node) + @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