Skip to content

Commit

Permalink
Add disconnect_on_error for redis-py 4.5.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed May 9, 2023
1 parent 620e22e commit 21d68bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
matrix:
redis-image: [ "redis:6.2.12", "redis:7.0.11" ]
python-version: [ "3.7", "3.10" ]
redis-py: [ "4.3.6", "4.5.4" ]
redis-py: [ "4.3.6", "4.5.5" ]
include:
- python-version: "3.11"
redis-image: "redis:6.2.12"
Expand Down
4 changes: 3 additions & 1 deletion fakeredis/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def _decode(self, response):
else:
return response

def read_response(self, disable_decoding=False):
def read_response(self, disable_decoding=False, disconnect_on_error=True):
if not self._server.connected:
try:
response = self._sock.responses.get_nowait()
except queue.Empty:
if disconnect_on_error:
self.disconnect()
raise redis.ConnectionError(msgs.CONNECTION_ERROR_MSG)
else:
response = self._sock.responses.get()
Expand Down
2 changes: 2 additions & 0 deletions fakeredis/aioredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ async def read_response(self, **kwargs):
try:
response = self._sock.responses.get_nowait()
except asyncio.QueueEmpty:
if kwargs.get('disconnect_on_error', True):
await self.disconnect()
raise redis_async.ConnectionError(msgs.CONNECTION_ERROR_MSG)
else:
timeout = kwargs.pop('timeout', None)
Expand Down

0 comments on commit 21d68bb

Please sign in to comment.