-
Notifications
You must be signed in to change notification settings - Fork 3
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
added get_replica_connections function #72
base: main
Are you sure you want to change the base?
Changes from 2 commits
e7beff6
6a717ab
0791c7e
c77580e
5ee68b7
c4dc33a
2c20a1e
99b6671
dd8a4ad
8eed87f
e646320
4a3d585
a1262e0
199a1e5
71622fe
9f261fc
9d21e95
6aad7bd
2a96be0
b693987
519b9dd
557f04f
222cfb4
a9f597e
ac8471e
cfd0864
65e41d0
d112322
ad7cedd
ac4cfa4
5a444db
4cc0b6a
51d4d90
cb8cd2e
1ad3162
4d4c1ac
263e8bf
af4f748
b1d6c41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from .sentinel import * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from .graph import Graph | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from typing import List, Union | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# config command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LIST_CMD = "GRAPH.LIST" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CONFIG_CMD = "GRAPH.CONFIG" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -75,6 +75,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dynamic_startup_nodes=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
url=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
address_remap=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
decode_responses=True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
conn = redis.Redis( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -92,7 +93,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
encoding_errors=encoding_errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
charset=charset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors=errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
decode_responses=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
decode_responses=decode_responses, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retry_on_timeout=retry_on_timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retry_on_error=retry_on_error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ssl=ssl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -125,6 +126,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.sentinel, self.service_name = Sentinel_Conn(conn, ssl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
conn = self.sentinel.master_for(self.service_name, ssl=ssl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if Is_Cluster(conn): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
conn = Cluster_Conn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
conn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -138,6 +140,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
address_remap, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.cluster_flag = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.connection = conn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.flushdb = conn.flushdb | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -225,6 +228,22 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.connection.execute_command(CONFIG_CMD, "GET", name)[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def get_replica_connections(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#decide if its Sentinel or cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redis_mode= self.connection.execute_command("info")['redis_mode'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if redis_mode == "standalone": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
replica_hostnames = self.sentinel.discover_slaves(service_name=self.service_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result = [(host,port) for host, port in replica_hostnames] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elif redis_mode == "cluster": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data = self.connection.cluster_nodes() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# List comprehension to get a list of (ip, port, hostname) tuples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
host_port_list = [(ip_port.split(':')[0], ip_port.split(':')[1], flag['hostname']) for ip_port, flag in data.items() if 'slave' in flag["flags"]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result = [tup for tup in host_port_list] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix several critical issues in implementation The method has multiple issues that need to be addressed:
Apply this diff to fix the issues: - redis_mode= self.connection.execute_command("info")['redis_mode']
+ redis_mode = self.connection.execute_command("info", section="server").get('redis_mode')
+ if not redis_mode:
+ raise ConnectionError("Unable to determine Redis mode")
+
if redis_mode == "standalone":
- replica_hostnames = self.sentinel.discover_slaves(service_name=self.service_name)
+ replica_hostnames = self.sentinel.discover_replicas(service_name=self.service_name)
result = [(host,port) for host, port in replica_hostnames]
return result
elif redis_mode == "cluster":
data = self.connection.cluster_nodes()
- # List comprehension to get a list of (ip, port, hostname) tuples
- host_port_list = [(ip_port.split(':')[0], ip_port.split(':')[1], flag['hostname']) for ip_port, flag in data.items() if 'slave' in flag["flags"]]
- result = [tup for tup in host_port_list]
+ result = []
+ for ip_port, flag in data.items():
+ if 'replica' in flag.get('flags', []): # Using 'replica' instead of 'slave'
+ host, port = ip_port.split(':')
+ result.append((host, int(port))) # Convert port to int for consistency
+ return result
-
+ else:
+ raise ValueError(f"Unsupported Redis mode: {redis_mode}") 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: codecov/patch[warning] 233-239: falkordb/falkordb.py#L233-L239 [warning] 241-243: falkordb/falkordb.py#L241-L243 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def config_set(self, name: str, value=None) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Update a DB level configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Update deprecated Redis terminology
The code uses deprecated 'slave' terminology. Redis has moved to more inclusive language.
Update the terminology:
Also applies to: 255-255