Skip to content

Commit dd0c492

Browse files
authored
Add force_master_ip support to async Sentinel client (#3524)
1 parent dbbe7a7 commit dd0c492

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

redis/asyncio/sentinel.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def __init__(
198198
sentinels,
199199
min_other_sentinels=0,
200200
sentinel_kwargs=None,
201+
force_master_ip=None,
201202
**connection_kwargs,
202203
):
203204
# if sentinel_kwargs isn't defined, use the socket_* options from
@@ -214,6 +215,7 @@ def __init__(
214215
]
215216
self.min_other_sentinels = min_other_sentinels
216217
self.connection_kwargs = connection_kwargs
218+
self._force_master_ip = force_master_ip
217219

218220
async def execute_command(self, *args, **kwargs):
219221
"""
@@ -277,7 +279,13 @@ async def discover_master(self, service_name: str):
277279
sentinel,
278280
self.sentinels[0],
279281
)
280-
return state["ip"], state["port"]
282+
283+
ip = (
284+
self._force_master_ip
285+
if self._force_master_ip is not None
286+
else state["ip"]
287+
)
288+
return ip, state["port"]
281289

282290
error_info = ""
283291
if len(collected_errors) > 0:

tests/test_asyncio/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ async def sentinel_setup(local_cache, request):
151151
for ip, port in (endpoint.split(":") for endpoint in sentinel_ips.split(","))
152152
]
153153
kwargs = request.param.get("kwargs", {}) if hasattr(request, "param") else {}
154+
force_master_ip = request.param.get("force_master_ip", None)
154155
sentinel = Sentinel(
155156
sentinel_endpoints,
157+
force_master_ip=force_master_ip,
156158
socket_timeout=0.1,
157159
client_cache=local_cache,
158160
protocol=3,

0 commit comments

Comments
 (0)