Python aioredis.RedisError() Examples
The following are 7
code examples of aioredis.RedisError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
aioredis
, or try the search function
.
Example #1
Source File: listener.py From resolwe with Apache License 2.0 | 6 votes |
def push_stats(self): """Push current stats to Redis.""" snapshot = self._make_stats() try: serialized = json.dumps(snapshot) await self._call_redis( aioredis.Redis.set, state.MANAGER_LISTENER_STATS, serialized ) await self._call_redis( aioredis.Redis.expire, state.MANAGER_LISTENER_STATS, 3600 ) except TypeError: logger.error( __("Listener can't serialize statistics:\n\n{}", traceback.format_exc()) ) except aioredis.RedisError: logger.error( __( "Listener can't store updated statistics:\n\n{}", traceback.format_exc(), ) )
Example #2
Source File: asyncio_redis_manager.py From python-socketio with MIT License | 6 votes |
def _publish(self, data): retry = True while True: try: if self.pub is None: self.pub = await aioredis.create_redis( (self.host, self.port), db=self.db, password=self.password, ssl=self.ssl ) return await self.pub.publish(self.channel, pickle.dumps(data)) except (aioredis.RedisError, OSError): if retry: self._get_logger().error('Cannot publish to redis... ' 'retrying') self.pub = None retry = False else: self._get_logger().error('Cannot publish to redis... ' 'giving up') break
Example #3
Source File: asyncio_redis_manager.py From python-socketio with MIT License | 6 votes |
def _listen(self): retry_sleep = 1 while True: try: if self.sub is None: self.sub = await aioredis.create_redis( (self.host, self.port), db=self.db, password=self.password, ssl=self.ssl ) self.ch = (await self.sub.subscribe(self.channel))[0] return await self.ch.get() except (aioredis.RedisError, OSError): self._get_logger().error('Cannot receive from redis... ' 'retrying in ' '{} secs'.format(retry_sleep)) self.sub = None await asyncio.sleep(retry_sleep) retry_sleep *= 2 if retry_sleep > 60: retry_sleep = 60
Example #4
Source File: sentinel_commands_test.py From aioredis with MIT License | 5 votes |
def test_ckquorum(redis_sentinel): assert (await redis_sentinel.check_quorum('master-no-fail')) # change quorum assert (await redis_sentinel.set('master-no-fail', 'quorum', 2)) with pytest.raises(RedisError): await redis_sentinel.check_quorum('master-no-fail') assert (await redis_sentinel.set('master-no-fail', 'quorum', 1)) assert (await redis_sentinel.check_quorum('master-no-fail'))
Example #5
Source File: listener.py From resolwe with Apache License 2.0 | 5 votes |
def _call_redis(self, meth, *args, **kwargs): """Perform a Redis call and handle connection dropping.""" while True: try: if not self._redis: self._redis = await self._make_connection() return await meth(self._redis, *args, **kwargs) except aioredis.RedisError: logger.exception("Redis connection error") if self._redis: self._redis.close() await self._redis.wait_closed() self._redis = None await asyncio.sleep(3)
Example #6
Source File: test_sanic.py From python-dockerflow with Mozilla Public License 2.0 | 5 votes |
def ping(self): if self.error == "connection": raise aioredis.ConnectionClosedError("fake") elif self.error == "redis": raise aioredis.RedisError("fake") elif self.error == "malformed": return b"PING" else: return b"PONG"
Example #7
Source File: checks.py From python-dockerflow with Mozilla Public License 2.0 | 4 votes |
def check_redis_connected(redis): """ A built-in check to connect to Redis using the given client and see if it responds to the ``PING`` command. It's automatically added to the list of Dockerflow checks if a :class:`~sanic_redis.SanicRedis` instance is passed to the :class:`~dockerflow.sanic.app.Dockerflow` class during instantiation, e.g.:: import redis as redislib from sanic import Sanic from dockerflow.sanic import Dockerflow app = Sanic(__name__) redis = redislib.from_url("redis://:password@localhost:6379/0") dockerflow = Dockerflow(app, redis=redis) An alternative approach to instantiating a Redis client directly would be using the `Sanic-Redis <https://github.com/strahe/sanic-redis>`_ Sanic extension:: from sanic import Sanic from sanic_redis import SanicRedis from dockerflow.sanic import Dockerflow app = Sanic(__name__) app.config['REDIS'] = {'address': 'redis://:password@localhost:6379/0'} redis = SanicRedis(app) dockerflow = Dockerflow(app, redis=redis) """ import aioredis errors = [] try: with await redis.conn as r: result = await r.ping() except aioredis.ConnectionClosedError as e: msg = "Could not connect to redis: {!s}".format(e) errors.append(Error(msg, id=health.ERROR_CANNOT_CONNECT_REDIS)) except aioredis.RedisError as e: errors.append( Error('Redis error: "{!s}"'.format(e), id=health.ERROR_REDIS_EXCEPTION) ) else: if result != b"PONG": errors.append(Error("Redis ping failed", id=health.ERROR_REDIS_PING_FAILED)) return errors