summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorChayim I. Kirshen <c@kirshen.com>2021-11-21 13:17:31 +0200
committerChayim I. Kirshen <c@kirshen.com>2021-11-21 13:17:31 +0200
commit1448a65e656a270caf4c6d3ba4eee5de04d0c4e1 (patch)
tree3b94bf968ef0d0d8b9820f8e8c390cab752df07a /redis/connection.py
parentd2b233384458869270352b8c99ca682ae480da5f (diff)
downloadredis-py-ck-binary-responses.tar.gz
Adding support for non-decodable commandsck-binary-responses
Some commands (i.e DUMP) should never have their response decoded, as they return binaries, not encoded blobs fixes #1254
Diffstat (limited to 'redis/connection.py')
-rwxr-xr-xredis/connection.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/redis/connection.py b/redis/connection.py
index e01742d..3de87ae 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -314,7 +314,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)
@@ -354,8 +354,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
@@ -449,7 +450,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)
@@ -742,10 +743,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" %