Browse Source

Correct handling of RedisError exception (Fixes #919)

pull/930/head
Miguel Grinberg 3 years ago
parent
commit
98318fbdde
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 11
      src/socketio/asyncio_redis_manager.py

11
src/socketio/asyncio_redis_manager.py

@ -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
@ -63,7 +66,7 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover
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')
@ -84,7 +87,7 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover
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))

Loading…
Cancel
Save