From 6c2d57ac8c7cc0c69c4fe2a05d40aed46205cca7 Mon Sep 17 00:00:00 2001 From: Guillaume Tassery Date: Fri, 16 Dec 2022 16:54:56 +0100 Subject: [PATCH] add timeout parameter for SentinelManagedConnection --- CHANGES | 1 + redis/asyncio/sentinel.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index b16fbce464..72b896b1b5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,4 @@ + * Add `timeout=None` in `SentinelConnectionManager.read_response` * Documentation fix: password protected socket connection (#2374) * Allow `timeout=None` in `PubSub.get_message()` to wait forever * add `nowait` flag to `asyncio.Connection.disconnect()` diff --git a/redis/asyncio/sentinel.py b/redis/asyncio/sentinel.py index 99c5074950..ec17886fc6 100644 --- a/redis/asyncio/sentinel.py +++ b/redis/asyncio/sentinel.py @@ -1,7 +1,7 @@ import asyncio import random import weakref -from typing import AsyncIterator, Iterable, Mapping, Sequence, Tuple, Type +from typing import AsyncIterator, Iterable, Mapping, Optional, Sequence, Tuple, Type from redis.asyncio.client import Redis from redis.asyncio.connection import ( @@ -63,9 +63,16 @@ async def connect(self): lambda error: asyncio.sleep(0), ) - async def read_response(self, disable_decoding: bool = False): + async def read_response( + self, + disable_decoding: bool = False, + timeout: Optional[float] = None, + ): try: - return await super().read_response(disable_decoding=disable_decoding) + return await super().read_response( + disable_decoding=disable_decoding, + timeout=timeout, + ) except ReadOnlyError: if self.connection_pool.is_master: # When talking to a master, a ReadOnlyError when likely