Skip to content

Commit a6a003c

Browse files
dvora-hchayim
andauthored
Add support for CLUSTER LINKS (#2019)
* cluster links * docstring * skip test Co-authored-by: Chayim <[email protected]>
1 parent 5d5f892 commit a6a003c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

redis/commands/cluster.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ def cluster_slots(self, target_nodes=None):
427427
"""
428428
return self.execute_command("CLUSTER SLOTS", target_nodes=target_nodes)
429429

430+
def cluster_links(self, target_node):
431+
"""
432+
Each node in a Redis Cluster maintains a pair of long-lived TCP link with each
433+
peer in the cluster: One for sending outbound messages towards the peer and one
434+
for receiving inbound messages from the peer.
435+
436+
This command outputs information of all such peer links as an array.
437+
438+
For more information check https://redis.io/commands/cluster-links
439+
"""
440+
return self.execute_command("CLUSTER LINKS", target_nodes=target_node)
441+
430442
def readonly(self, target_nodes=None):
431443
"""
432444
Enables read queries.

tests/test_cluster.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,17 @@ def test_cluster_replicas(self, r):
10291029
== "r4xfga22229cf3c652b6fca0d09ff69f3e0d4d"
10301030
)
10311031

1032+
@skip_if_server_version_lt("7.0.0")
1033+
def test_cluster_links(self, r):
1034+
node = r.get_random_node()
1035+
res = r.cluster_links(node)
1036+
links_to = sum(x.count("to") for x in res)
1037+
links_for = sum(x.count("from") for x in res)
1038+
assert links_to == links_for
1039+
print(res)
1040+
for i in range(0, len(res) - 1, 2):
1041+
assert res[i][3] == res[i + 1][3]
1042+
10321043
def test_readonly(self):
10331044
r = get_mocked_redis_client(host=default_host, port=default_port)
10341045
mock_all_nodes_resp(r, "OK")

0 commit comments

Comments
 (0)