Skip to content

Commit

Permalink
Kristjan/issue redis#2754: Add missing argument to SentinelManagedCon…
Browse files Browse the repository at this point in the history
…nection.read_response() (redis#2756)

* Increase timeout for a test which would hang completely if failing.
Timeouts in virtualized CI backends can occasionally fail if too short.

* add "disconnect_on_error" argument to SentinelManagedConnection

* update Changes

* lint
  • Loading branch information
kristjanvalur authored and mmahadikar-ns committed Jun 9, 2023
1 parent f056118 commit 994af3e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Fix #2754, adding a missing argument to SentinelManagedConnection
* Fix `xadd` command to accept non-negative `maxlen` including 0
* Revert #2104, #2673, add `disconnect_on_error` option to `read_response()` (issues #2506, #2624)
* Add `address_remap` parameter to `RedisCluster`
Expand Down
3 changes: 3 additions & 0 deletions redis/asyncio/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ async def read_response(
self,
disable_decoding: bool = False,
timeout: Optional[float] = None,
*,
disconnect_on_error: Optional[float] = True,
):
try:
return await super().read_response(
disable_decoding=disable_decoding,
timeout=timeout,
disconnect_on_error=disconnect_on_error,
)
except ReadOnlyError:
if self.connection_pool.is_master:
Expand Down
10 changes: 8 additions & 2 deletions redis/sentinel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import weakref
from typing import Optional

from redis.client import Redis
from redis.commands import SentinelCommands
Expand Down Expand Up @@ -53,9 +54,14 @@ def _connect_retry(self):
def connect(self):
return self.retry.call_with_retry(self._connect_retry, lambda error: None)

def read_response(self, disable_decoding=False):
def read_response(
self, disable_decoding=False, *, disconnect_on_error: Optional[bool] = False
):
try:
return super().read_response(disable_decoding=disable_decoding)
return super().read_response(
disable_decoding=disable_decoding,
disconnect_on_error=disconnect_on_error,
)
except ReadOnlyError:
if self.connection_pool.is_master:
# When talking to a master, a ReadOnlyError when likely
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,7 @@ async def helper():
# the task is now sleeping, lets send it an exception
task.cancel()
# If all is well, the task should finish right away, otherwise fail with Timeout
async with async_timeout(0.1):
async with async_timeout(1.0):
await task


Expand Down

0 comments on commit 994af3e

Please sign in to comment.