Skip to content

Commit 646df07

Browse files
committed
Perform connect() call in PubSub code rather than read_response.
1 parent cabbb15 commit 646df07

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
@@ -920,8 +920,6 @@ async def can_read(self, timeout: float = 0):
920920

921921
async def read_response(self, disable_decoding: bool = False):
922922
"""Read the response from a previously sent command"""
923-
if not self.is_connected:
924-
await self.connect()
925923
try:
926924
async with self._lock:
927925
if self.socket_timeout:

redis/client.py

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

14961496
self.check_health()
14971497

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

15021508
if self.is_health_check_response(response):
15031509
# 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)