Skip to content

Commit 1d5f029

Browse files
committed
Perform connect() call in PubSub code rather than read_response.
1 parent 19ead64 commit 1d5f029

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

redis/asyncio/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,15 @@ async def parse_response(self, block: bool = True, timeout: float = 0):
754754

755755
await self.check_health()
756756

757-
if not block and not await self._execute(conn, conn.can_read, timeout=timeout):
758-
return None
759-
response = await self._execute(conn, conn.read_response)
757+
async def try_read():
758+
if not block:
759+
if not await conn.can_read(timeout=timeout):
760+
return None
761+
else:
762+
await conn.connect()
763+
return await conn.read_response()
764+
765+
response = await self._execute(conn, try_read)
760766

761767
if conn.health_check_interval and response == self.health_check_response:
762768
# ignore the health check message as user might not expect it

redis/asyncio/connection.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,6 @@ async def can_read(self, timeout: float = 0):
930930

931931
async def read_response(self, disable_decoding: bool = False):
932932
"""Read the response from a previously sent command"""
933-
if not self.is_connected:
934-
await self.connect()
935933
try:
936934
async with self._lock:
937935
if self.socket_timeout:

redis/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,15 @@ def parse_response(self, block=True, timeout=0):
14971497

14981498
self.check_health()
14991499

1500-
if not block and not self._execute(conn, conn.can_read, timeout=timeout):
1501-
return None
1502-
response = self._execute(conn, conn.read_response)
1500+
def try_read():
1501+
if not block:
1502+
if not conn.can_read(timeout=timeout):
1503+
return None
1504+
else:
1505+
conn.connect()
1506+
return conn.read_response()
1507+
1508+
response = self._execute(conn, try_read)
15031509

15041510
if self.is_health_check_response(response):
15051511
# ignore the health check message as user might not expect it

redis/connection.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,6 @@ def can_read(self, timeout=0):
815815

816816
def read_response(self, disable_decoding=False):
817817
"""Read the response from a previously sent command"""
818-
if not self._sock:
819-
self.connect()
820818
try:
821819
hosterr = f"{self.host}:{self.port}"
822820
except AttributeError:

0 commit comments

Comments
 (0)