Skip to content

Add support for CLUSTER LINKS #2019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down