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


Python redis.RedisError方法代码示例

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


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

示例1: load_strategys

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def load_strategys(self):
        uuid_strategy_map = {}
        conn = get_config_redis_client()
        logger.info('start load strategys from db, current strategy: %s',
                    self.uuid_strategy_map.keys())
        for strategy_cls in _used_strategies:
            try:
                for name in conn.scan_iter(match=strategy_cls.prefix):
                    d = conn.hgetall(name)
                    strategy = strategy_cls(d)
                    uuid_strategy_map[strategy.uuid] = strategy
            except redis.RedisError:
                logger.error('load strategys occur redis conn error')
                return
        self.uuid_strategy_map = uuid_strategy_map
        logger.info('load strategys success, current strategy: %s',
                    self.uuid_strategy_map.keys()) 
开发者ID:momosecurity,项目名称:aswan,代码行数:19,代码来源:strategy.py

示例2: load_raw_source

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def load_raw_source(cls):
        conn = get_config_redis_client()
        name_keys_map = {}

        try:
            d = conn.hgetall(conf.REDIS_SOURCE_MAP)
        except redis.RedisError:
            logger.exception('load raw sources error')
            return

        for name, fields_str in d.items():
            fields = json.loads(fields_str)
            fields.pop('name_show', None)
            keys = {}
            for key_name, key_type in fields.items():
                if key_type in {'string', 'str'}:
                    key_type = 'str'
                try:
                    type_ = getattr(__builtins__, key_type)
                except AttributeError:
                    type_ = __builtins__[key_type]
                keys[key_name] = type_
            name_keys_map[name] = keys

        cls.name_keys_map = name_keys_map 
开发者ID:momosecurity,项目名称:aswan,代码行数:27,代码来源:source.py

示例3: _write_one_record

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def _write_one_record(self, zkey, score, member, preserve_time):
        pipeline = self.conn.pipeline()
        try:
            pipeline.zadd(zkey, score, member)
            pipeline.expire(zkey, preserve_time)
            # 这个是为了减少redis存储压力,每次删除部分老旧数据,可以修改此处逻辑
            pipeline.zremrangebyrank(zkey, 0, -128)
            pipeline.execute()
        except redis.RedisError:
            logger.error(
                f'pipeline execute error,'
                f'zkey --> {zkey},'
                f'score --> {score},'
                f'member --> {member},'
                f'preserve_time --> {preserve_time})')
            return False
        return True 
开发者ID:momosecurity,项目名称:aswan,代码行数:19,代码来源:source.py

示例4: load_rules

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def load_rules(self):
        id_rule_map = {}
        conn = get_config_redis_client()
        logger.info('start load rules, current rule ids: %s',
                    self.id_rule_map.keys())
        try:
            for name in conn.scan_iter(match='rule:*'):
                d = conn.hgetall(name)
                if self._should_load(d):
                    rule = Rule(d)
                    id_rule_map[rule.id] = rule
        except redis.RedisError:
            logger.error('load rules occur redis conn error')
            return
        self.id_rule_map = id_rule_map
        logger.info('load rules success, current rule ids: %s',
                    self.id_rule_map.keys()) 
开发者ID:momosecurity,项目名称:aswan,代码行数:19,代码来源:rule.py

示例5: limit

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def limit(self, client, ignore_redis_error=False):
        if self._limiter is None:
            return dummy_limit()

        @contextmanager
        def limit():
            try:
                with self._limiter.limit(client):
                    yield
            except RedisError as e:
                if ignore_redis_error:
                    logger.warning(
                        "Ignoring RedisError in rate limiter for %s",
                        self._limiter.resource,
                        exc_info=True,
                    )
                    yield
                else:
                    raise

        return limit() 
开发者ID:QwantResearch,项目名称:idunn,代码行数:23,代码来源:rate_limiter.py

示例6: cluster_health

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def cluster_health(self):
        '''
        Polls redis for current cluster status.
        If a node has failed repeatedly, the apps on it will be offloaded
        '''
        if self.role != 'master':
            return
        self.monaco.refresh(self.r)
        offload = []
        for node_id in self.monaco.node_ids:
            node = schema.MonacoNode(node_id=node_id)
            node.refresh(self.r)
            if node.hostname == self.hostname:
                continue
            try:
                nodecli = redis.StrictRedis(host=node.hostname, port=config['mgmt_port'], socket_connect_timeout=1, socket_timeout=1)
                nodecli.info()
                self.monaco.node_up(node_id, self.r)
                self.logger.debug('Node %s is healthy', node_id)
            except redis.RedisError, exc:
                self.logger.warn('Node %s missed a healthcheck', node_id)
                if self.monaco.node_down(node_id, self.r):
                    self.logger.error('Node %s has been marked down', node_id)
                    self.logger.exception(exc)
                    offload.append(node_id) 
开发者ID:hulu,项目名称:monaco,代码行数:27,代码来源:master.py

示例7: update_subs

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def update_subs(self):
        '''
        Subscribes the slave to the channels associated with the
        '''
        try:
            with self.lock:
                channels = self._subscriptions.keys()

                subs = {}
                self.node.refresh(self.r)
                subs[keysub(schema.NODE_APPS_TMPL % self.node.node_id)] = self.node_handler_factory()
                subs[keysub(schema.NODE_TWEMS_TMPL % self.node.node_id)] = self.twem_handler_factory()
                for app_id in self.node.apps:
                    subs[keysub(schema.APP_CLUSTER_TMPL % app_id)] = self.app_handler_factory(app_id)
                    subs[keysub(schema.APP_HASH_TMPL % app_id)] = self.app_config_handler_factory(app_id)
                map(self._remove_subscription, [chan for chan in channels if chan not in subs.keys()])
                for k, v in subs.iteritems():
                    self._add_subscription(k, v)
        except redis.RedisError, err:
            self.logger.exception(err)
            self.r = redis.StrictRedis(port=config['mgmt_port']) 
开发者ID:hulu,项目名称:monaco,代码行数:23,代码来源:slave.py

示例8: hash_update

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def hash_update(key, hashdata, r):
    '''
    Atomically update the redis hash at <key>
    Set the values from the dict <hashdata>, using client <r>
    '''
    if hasattr(hash_update, 'script'):
        try:
            hash_update.script(args=[key] + [item for tup in hashdata.items() for item in tup], client=r)
            return
        except redis.RedisError:
            pass
    path = os.path.join(os.path.dirname(__file__), 'lua/hash_update.lua')
    with open(path) as scriptfile:
        script = scriptfile.read()
    hash_update.script = r.register_script(script)
    hash_update.script(args=[key] + [item for tup in hashdata.items() for item in tup], client=r) 
开发者ID:hulu,项目名称:monaco,代码行数:18,代码来源:schema.py

示例9: hash_write

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def hash_write(key, hashdata, r):
    '''
    Atomically overwrite the redis hash at <key>
    Setting it equal to the dict <hashdata>, using client <r>
    '''
    if hasattr(hash_write, 'script'):
        try:
            hash_write.script(args=[key] + [item for tup in hashdata.items() for item in tup], client=r)
            return
        except redis.RedisError:
            pass
    path = os.path.join(os.path.dirname(__file__), 'lua/hash_write.lua')
    with open(path) as scriptfile:
        script = scriptfile.read()
    hash_write.script = r.register_script(script)
    hash_write.script(args=[key] + [item for tup in hashdata.items() for item in tup], client=r) 
开发者ID:hulu,项目名称:monaco,代码行数:18,代码来源:schema.py

示例10: consume_events

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def consume_events(self):
        self._is_running = True
        while self._loop.is_running() and self._is_running:
            try:
                msg = await asyncio.wait_for(self._queue.get(), timeout=1)
                if not msg:
                    self._is_running = False
                    return
                await _ensure_coroutine_function(self._callback)(msg)
                try:
                    self._counter[msg.stream] = msg.sequence
                except pybreaker.CircuitBreakerError:
                    pass
                except redis.RedisError:
                    self._logger.warn("Failed to persist last read event")
            except RejectedMessageException:
                self._logger.warn("%s message %s was rejected and has not been processed",
                                  msg.type, msg.id)
            except asyncio.TimeoutError:
                self._is_running = False
            except:
                self._logger.exception("Failed to process message %s", msg)
                self._is_running = False 
开发者ID:madedotcom,项目名称:atomicpuppy,代码行数:25,代码来源:atomicpuppy.py

示例11: get_list

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def get_list(self):
        server_list = []
        try:
            server_key_list = self._redis_client.keys(pattern='januscloud:backend_servers:*')
            start = 0
            step = 32
            total = len(server_key_list)
            while True:
                with self._redis_client.pipeline() as p:
                    for server_key in server_key_list[start:start+step]:
                        p.hgetall(server_key)
                    result = p.execute()
                    for rd_server in result:
                        if rd_server:
                            server_list.append(self._from_rd_server(rd_server))
                start += step
                if start >= total:
                    break
        except RedisError as e:
            log.warning('Fail to get backend server list because of Redis client error: {}'.format(e))

        return server_list 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:24,代码来源:rd_server_dao.py

示例12: handle_redis_except

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def handle_redis_except(f):
    """Wrapper which handles Redis exceptions."""
    # noqa
    @wraps(f)
    def decorated_function(*args, **kwargs):
        """Represents decorated function."""
        try:
            return f(*args, **kwargs)
        except (RedisError, OSError) as e:
            error_code = REDIS_EXCEPTION_ERROR_CODE

            return jsonify(error={
                'code': error_code,
                'reason': e.messages,
            })

    return decorated_function 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:19,代码来源:decorators.py

示例13: start_consuming_message

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def start_consuming_message(queue_name, consume_function, threads_num=50):
    """
    本例子实现的功能和中间件过于简单,单一函数最好了。
    看不懂有类的代码,不用看上面那个类,看这个函数就可以,使用一个10行代码的函数实现乞丐版分布式函数执行框架。

    """
    pool = ThreadPoolExecutor(threads_num)
    while True:
        try:
            redis_task = redis_db_frame.brpop(queue_name, timeout=60)
            if redis_task:
                task_str = redis_task[1].decode()
                print(f'从redis的 {queue_name} 队列中 取出的消息是: {task_str}')
                pool.submit(consume_function, **json.loads(task_str))
            else:
                print(f'redis的 {queue_name} 队列中没有任务')
        except redis.RedisError as e:
            print(e) 
开发者ID:ydf0509,项目名称:distributed_framework,代码行数:20,代码来源:beggar_redis_consumer.py

示例14: publish_event_data

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def publish_event_data(self, event_id, data_obj):
        """
        Publishes the serialized form of the data object for the given event.

        Note that this occurs in a thread to prevent blocking.
        """

        def conduct():
            try:
                self.publish_event_data_sync(event_id, data_obj)
                logger.debug("Published user event %s: %s", event_id, data_obj)
            except redis.RedisError:
                logger.exception("Could not publish user event")

        thread = threading.Thread(target=conduct)
        thread.start() 
开发者ID:quay,项目名称:quay,代码行数:18,代码来源:userevent.py

示例15: acquire

# 需要导入模块: import redis [as 别名]
# 或者: from redis import RedisError [as 别名]
def acquire(self):
        logger.debug("Acquiring global lock %s", self._lock_name)
        try:
            self._redlock = RedLock(
                self._lock_name, connection_details=[self._redis_info], ttl=self._lock_ttl
            )
            acquired = self._redlock.acquire()
            if not acquired:
                logger.debug("Was unable to not acquire lock %s", self._lock_name)
                return False

            logger.debug("Acquired lock %s", self._lock_name)
            return True
        except RedLockError:
            logger.debug("Could not acquire lock %s", self._lock_name)
            return False
        except RedisError as re:
            logger.debug("Could not connect to Redis for lock %s: %s", self._lock_name, re)
            return False 
开发者ID:quay,项目名称:quay,代码行数:21,代码来源:locking.py


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