From d7b56103ed4d0ba9c05c74ca5580c72fcb70c09c Mon Sep 17 00:00:00 2001 From: Chayim Date: Thu, 25 Nov 2021 14:18:33 +0200 Subject: Adding support for non-decodable commands (#1731) --- redis/connection.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'redis/connection.py') diff --git a/redis/connection.py b/redis/connection.py index eac9db3..2f91fae 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -315,7 +315,7 @@ class PythonParser(BaseParser): def can_read(self, timeout): return self._buffer and self._buffer.can_read(timeout) - def read_response(self): + def read_response(self, disable_decoding=False): raw = self._buffer.readline() if not raw: raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR) @@ -355,8 +355,9 @@ class PythonParser(BaseParser): length = int(response) if length == -1: return None - response = [self.read_response() for i in range(length)] - if isinstance(response, bytes): + response = [self.read_response(disable_decoding=disable_decoding) + for i in range(length)] + if isinstance(response, bytes) and disable_decoding is False: response = self.encoder.decode(response) return response @@ -450,7 +451,7 @@ class HiredisParser(BaseParser): if custom_timeout: sock.settimeout(self._socket_timeout) - def read_response(self): + def read_response(self, disable_decoding=False): if not self._reader: raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR) @@ -758,10 +759,12 @@ class Connection: self.connect() return self._parser.can_read(timeout) - def read_response(self): + def read_response(self, disable_decoding=False): """Read the response from a previously sent command""" try: - response = self._parser.read_response() + response = self._parser.read_response( + disable_decoding=disable_decoding + ) except socket.timeout: self.disconnect() raise TimeoutError("Timeout reading from %s:%s" % -- cgit v1.2.1