Skip to content

Commit 99b6671

Browse files
added error handling
1 parent 2c20a1e commit 99b6671

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

falkordb/falkordb.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,19 @@ def get_replica_connections(self):
245245
ValueError: If the `mode` is neither Sentinel nor Cluster.
246246
"""
247247
# decide if it's Sentinel or cluster
248-
mode = self.connection.execute_command("info")['redis_mode']
248+
try:
249+
mode = self.connection.execute_command("info")['redis_mode']
250+
except Exception as e:
251+
raise Exception(f"Failed to get Redis mode: {e}")
252+
249253
if hasattr(self, 'sentinel') and self.sentinel is not None:
250254
replica_hostnames = self.sentinel.discover_slaves(service_name=self.service_name)
251-
return [(host, port) for host, port in replica_hostnames]
255+
return [(host, int(port)) for host, port in replica_hostnames]
252256
elif mode == "cluster":
253257
data = self.connection.cluster_nodes()
254-
return [(flag['hostname'], ip_port.split(':')[1]) for ip_port, flag in data.items() if 'slave' in flag["flags"]]
258+
return [(flag['hostname'], int(ip_port.split(':')[1])) for ip_port, flag in data.items() if 'slave' in flag["flags"] and flag["hostname"]]
255259
else:
256-
raise ValueError(f"Unsupported Redis mode: {redis_mode}")
260+
raise ValueError(f"Unsupported Redis mode: {mode}")
257261

258262

259263

0 commit comments

Comments
 (0)