當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。