def read_response(self):
if not self._stream:
raise ConnectionError("Socket closed on remote end")
# _next_response might be cached from a can_read() call
if self._next_response is not False:
response = self._next_response
self._next_response = False
return response
response = self._reader.gets()
while response is False:
try:
buffer = await self._stream.read(self._read_size)
# CancelledError will be caught by client so that command won't be retried again
# For more detailed discussion please see https://github.com/NoneGG/aredis/issues/56
except CancelledError:
raise
except Exception:
e = sys.exc_info()[1]
raise ConnectionError("Error {} while reading from stream: {}".format(type(e), e.args))
if not buffer:
raise ConnectionError("Socket closed on remote end")
self._reader.feed(buffer)
response = self._reader.gets()
if isinstance(response, ResponseError):
response = self.parse_error(response.args[0])
return response
评论列表
文章目录