From 98318fbdde2c4dcfba15d1b0aaf266b599e81e0c Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 1 May 2022 15:51:31 +0100 Subject: [PATCH] Correct handling of RedisError exception (Fixes #919) --- src/socketio/asyncio_redis_manager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/socketio/asyncio_redis_manager.py b/src/socketio/asyncio_redis_manager.py index 0cedfdc..9e3d954 100644 --- a/src/socketio/asyncio_redis_manager.py +++ b/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))