Skip to content

Commit 27addb5

Browse files
committed
expand with statement to avoid invoking null context managers.
1 parent 8a16d5f commit 27addb5

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

redis/asyncio/connection.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,26 @@ async def read_response(
895895
):
896896
"""Read the response from a previously sent command"""
897897
read_timeout = timeout if timeout is not None else self.socket_timeout
898-
lock_ctxt = self._lock if with_lock else nullcontext
899898
try:
900-
async with lock_ctxt, async_timeout.timeout(read_timeout):
901-
response = await self._parser.read_response(
902-
disable_decoding=disable_decoding
903-
)
899+
if with_lock:
900+
if read_timeout is not None:
901+
async with self._lock, async_timeout.timeout(read_timeout):
902+
response = await self._parser.read_response(
903+
disable_decoding=disable_decoding
904+
)
905+
else:
906+
async with self._lock:
907+
self._parser.read_response(disable_decoding=disable_decoding)
908+
else:
909+
if read_timeout is not None:
910+
async with async_timeout.timeout(read_timeout):
911+
response = await self._parser.read_response(
912+
disable_decoding=disable_decoding
913+
)
914+
else:
915+
response = await self._parser.read_response(
916+
disable_decoding=disable_decoding
917+
)
904918
except asyncio.TimeoutError:
905919
if timeout is not None:
906920
# user requested timeout, return None

0 commit comments

Comments
 (0)