Skip to content

Commit

Permalink
Add force_master_ip support to async Sentinel client
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrovcin committed Feb 22, 2025
1 parent 75cac31 commit a9aa012
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion redis/asyncio/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def __init__(
sentinels,
min_other_sentinels=0,
sentinel_kwargs=None,
force_master_ip=None,
**connection_kwargs,
):
# if sentinel_kwargs isn't defined, use the socket_* options from
Expand All @@ -214,6 +215,7 @@ def __init__(
]
self.min_other_sentinels = min_other_sentinels
self.connection_kwargs = connection_kwargs
self._force_master_ip = force_master_ip

async def execute_command(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -277,7 +279,13 @@ async def discover_master(self, service_name: str):
sentinel,
self.sentinels[0],
)
return state["ip"], state["port"]

ip = (
self._force_master_ip
if self._force_master_ip is not None
else state["ip"]
)
return ip, state["port"]

error_info = ""
if len(collected_errors) > 0:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asyncio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ async def sentinel_setup(local_cache, request):
for ip, port in (endpoint.split(":") for endpoint in sentinel_ips.split(","))
]
kwargs = request.param.get("kwargs", {}) if hasattr(request, "param") else {}
force_master_ip = request.param.get("force_master_ip", None)
sentinel = Sentinel(
sentinel_endpoints,
force_master_ip=force_master_ip,
socket_timeout=0.1,
client_cache=local_cache,
protocol=3,
Expand Down

0 comments on commit a9aa012

Please sign in to comment.