当前位置: 首页>>代码示例>>Python>>正文


Python aioredis.RedisError方法代码示例

本文整理汇总了Python中aioredis.RedisError方法的典型用法代码示例。如果您正苦于以下问题:Python aioredis.RedisError方法的具体用法?Python aioredis.RedisError怎么用?Python aioredis.RedisError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aioredis的用法示例。


在下文中一共展示了aioredis.RedisError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: push_stats

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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(),
                )
            ) 
开发者ID:genialis,项目名称:resolwe,代码行数:24,代码来源:listener.py

示例2: _publish

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:23,代码来源:asyncio_redis_manager.py

示例3: _listen

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:22,代码来源:asyncio_redis_manager.py

示例4: test_ckquorum

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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')) 
开发者ID:aio-libs,项目名称:aioredis,代码行数:14,代码来源:sentinel_commands_test.py

示例5: _call_redis

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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) 
开发者ID:genialis,项目名称:resolwe,代码行数:16,代码来源:listener.py

示例6: ping

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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" 
开发者ID:mozilla-services,项目名称:python-dockerflow,代码行数:11,代码来源:test_sanic.py

示例7: check_redis_connected

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import RedisError [as 别名]
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 
开发者ID:mozilla-services,项目名称:python-dockerflow,代码行数:52,代码来源:checks.py


注:本文中的aioredis.RedisError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。