From 4b404120f488fcdd335c60df844fb4acfc5c89d1 Mon Sep 17 00:00:00 2001 From: Bar Shaul Date: Tue, 23 Nov 2021 16:48:59 +0200 Subject: [PATCH] 1) Fixes issue #1740. 2) Changed health check to be executed from the execute_command method only in the first command execution. --- redis/client.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/redis/client.py b/redis/client.py index d7a924f321..a7511fa0d9 100755 --- a/redis/client.py +++ b/redis/client.py @@ -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() @@ -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