Skip to content

Commit

Permalink
1) Fixes issue redis#1740. 2) Changed health check to be executed fro…
Browse files Browse the repository at this point in the history
…m the execute_command method only in the first command execution.
  • Loading branch information
barshaul committed Dec 8, 2021
1 parent c2ebd78 commit 4b40412
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,12 +1282,14 @@ def __init__(
self.encoder = encoder
if self.encoder is None:
self.encoder = self.connection_pool.get_encoder()
self.health_check_response_b = self.encoder.encode(
self.HEALTH_CHECK_MESSAGE)
if self.encoder.decode_responses:
self.health_check_response = ["pong", self.HEALTH_CHECK_MESSAGE]
else:
self.health_check_response = [
b"pong",
self.encoder.encode(self.HEALTH_CHECK_MESSAGE),
self.health_check_response_b
]
self.reset()

Expand Down Expand Up @@ -1401,7 +1403,14 @@ def parse_response(self, block=True, timeout=0):
return None
response = self._execute(conn, conn.read_response)

if conn.health_check_interval and response == self.health_check_response:
if conn.health_check_interval and \
response in [
self.health_check_response, # If there was a subscription
self.health_check_response_b # If there wasn't
]:
# If there are no subscriptions redis responds to PING command with
# a bulk response, instead of a multi-bulk with "pong" and the
# response.
# ignore the health check message as user might not expect it
return None
return response
Expand Down

0 comments on commit 4b40412

Please sign in to comment.