Skip to content

Commit

Permalink
Correct handling of RedisError exception (Fixes #919)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 1, 2022
1 parent 268fe12 commit 98318fb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/socketio/asyncio_redis_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import asyncio
import pickle

try:
try: # pragma: no cover
from redis import asyncio as aioredis
except ImportError:
from redis.exceptions import RedisError
except ImportError: # pragma: no cover
try:
import aioredis
from aioredis.exceptions import RedisError
except ImportError:
aioredis = None
RedisError = None

from .asyncio_pubsub_manager import AsyncPubSubManager

Expand Down Expand Up @@ -63,7 +66,7 @@ async def _publish(self, data):
self._redis_connect()
return await self.redis.publish(
self.channel, pickle.dumps(data))
except aioredis.exceptions.RedisError:
except RedisError:
if retry:
self._get_logger().error('Cannot publish to redis... '
'retrying')
Expand All @@ -84,7 +87,7 @@ async def _redis_listen_with_retries(self):
retry_sleep = 1
async for message in self.pubsub.listen():
yield message
except aioredis.exceptions.RedisError:
except RedisError:
self._get_logger().error('Cannot receive from redis... '
'retrying in '
'{} secs'.format(retry_sleep))
Expand Down

0 comments on commit 98318fb

Please sign in to comment.