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 asyncio
import pickle import pickle
try: try: # pragma: no cover
from redis import asyncio as aioredis from redis import asyncio as aioredis
except ImportError: from redis.exceptions import RedisError
except ImportError: # pragma: no cover
try: try:
import aioredis import aioredis
from aioredis.exceptions import RedisError
except ImportError: except ImportError:
aioredis = None aioredis = None
RedisError = None
from .asyncio_pubsub_manager import AsyncPubSubManager from .asyncio_pubsub_manager import AsyncPubSubManager
@ -63,7 +66,7 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover
self._redis_connect() self._redis_connect()
return await self.redis.publish( return await self.redis.publish(
self.channel, pickle.dumps(data)) self.channel, pickle.dumps(data))
except aioredis.exceptions.RedisError: except RedisError:
if retry: if retry:
self._get_logger().error('Cannot publish to redis... ' self._get_logger().error('Cannot publish to redis... '
'retrying') 'retrying')
@ -84,7 +87,7 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover
retry_sleep = 1 retry_sleep = 1
async for message in self.pubsub.listen(): async for message in self.pubsub.listen():
yield message yield message
except aioredis.exceptions.RedisError: except RedisError:
self._get_logger().error('Cannot receive from redis... ' self._get_logger().error('Cannot receive from redis... '
'retrying in ' 'retrying in '
'{} secs'.format(retry_sleep)) '{} secs'.format(retry_sleep))

Loading…
Cancel
Save