Skip to content

Add retries to connections in Sentinel Pools #1879

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 2 commits into from
Jan 17, 2022
Merged
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
8 changes: 7 additions & 1 deletion redis/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def connect_to(self, address):
if str_if_bytes(self.read_response()) != "PONG":
raise ConnectionError("PING failed")

def connect(self):
def _connect_retry(self):
if self._sock:
return # already connected
if self.connection_pool.is_master:
Expand All @@ -50,6 +50,12 @@ def connect(self):
continue
raise SlaveNotFoundError # Never be here

def connect(self):
return self.retry.call_with_retry(
self._connect_retry,
lambda error: None,
)

def read_response(self, disable_decoding=False):
try:
return super().read_response(disable_decoding=disable_decoding)
Expand Down