Skip to content

Commit 4598d80

Browse files
committed
add "disconnect_on_error" argument to SentinelManagedConnection
1 parent 3651506 commit 4598d80

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

redis/asyncio/sentinel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ async def read_response(
6767
self,
6868
disable_decoding: bool = False,
6969
timeout: Optional[float] = None,
70+
*,
71+
disconnect_on_error: Optional[float] = True,
7072
):
7173
try:
7274
return await super().read_response(
7375
disable_decoding=disable_decoding,
7476
timeout=timeout,
77+
disconnect_on_error=disconnect_on_error,
7578
)
7679
except ReadOnlyError:
7780
if self.connection_pool.is_master:

redis/sentinel.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from redis.connection import Connection, ConnectionPool, SSLConnection
77
from redis.exceptions import ConnectionError, ReadOnlyError, ResponseError, TimeoutError
88
from redis.utils import str_if_bytes
9+
from typing import Optional
910

1011

1112
class MasterNotFoundError(ConnectionError):
@@ -53,9 +54,14 @@ def _connect_retry(self):
5354
def connect(self):
5455
return self.retry.call_with_retry(self._connect_retry, lambda error: None)
5556

56-
def read_response(self, disable_decoding=False):
57+
def read_response(
58+
self, disable_decoding=False, *, disconnect_on_error: Optional[bool] = False
59+
):
5760
try:
58-
return super().read_response(disable_decoding=disable_decoding)
61+
return super().read_response(
62+
disable_decoding=disable_decoding,
63+
disconnect_on_error=disconnect_on_error,
64+
)
5965
except ReadOnlyError:
6066
if self.connection_pool.is_master:
6167
# When talking to a master, a ReadOnlyError when likely

0 commit comments

Comments
 (0)