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


Python exceptions.RedisError方法代码示例

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


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

示例1: word_vec

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def word_vec(self, word):  # pylint: disable=E0202
        """
        This method is mimicking the word_vec method from the Gensim KeyedVector class. Instead of
        looking it up from an in memory dict, it
        - requests the value from the redis instance, where the key is a combination between
        an optional word vector model key and the word itself
        - decompresses it
        - and finally unpickles it

        :param word: string

        :returns: numpy array of dim of the word vector model (for Google: 300, 1)
        """

        try:
            cache_entry = self._redis.hget(self.key, word)
            if not cache_entry:
                raise KeyError(f'Key {word} does not exist in cache')
            return pickle.loads(cache_entry)
        except RedisError as exception:
            raise RedisKeyedVectorException(f'The connection to Redis failed while trying to '
                                            f'retrieve a word vector. Redis error message: '
                                            f'{exception}')
        except TypeError:
            return None 
开发者ID:textpipe,项目名称:textpipe,代码行数:27,代码来源:wrappers.py

示例2: load_keyed_vectors_into_redis

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def load_keyed_vectors_into_redis(self, model_path, idf_weighting='naive'):
        """
        This function loops over all available words in the loaded word2vec keyed vectors model
        and loads them into the redis instance.
        """
        model = KeyedVectors.load(model_path, mmap='r')
        nr_train_tokens = sum(token_vocab.count for token_vocab in model.vocab.values())
        self.idf_weighting = idf_weighting
        try:
            for word in tqdm(list(model.vocab.keys())):
                if self.idf_weighting == 'naive':
                    idf = model.vocab[word].count
                elif self.idf_weighting == 'log':
                    idf = np.log(nr_train_tokens / (model.vocab[word].count + 1)) + 1
                else:
                    raise ValueError(f'idf_weighting "{self.idf_weighting}" not available; use '
                                     f'"naive" or "log"')
                idf_normalized_vector = model[word] / idf
                self._redis.hset(self.key, word, pickle.dumps(idf_normalized_vector))
        except RedisError as exception:
            raise RedisKeyedVectorException(f'RedisError while trying to load model {model} '
                                            f'into redis: {exception}')
        del model 
开发者ID:textpipe,项目名称:textpipe,代码行数:25,代码来源:wrappers.py

示例3: exception_handler

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def exception_handler(exc, context):
    """
    自定义异常处理
    :param exc: 别的地方抛的异常就会传给exc
    :param context: 字典形式。抛出异常的上下文(即抛出异常的出处;即抛出异常的视图)
    :return: Response响应对象
    """
    # 调用drf框架原生的异常处理方法,把异常和异常出处交给他处理,如果是序列化器异常就直接处理,处理之后就直接返回
    response = drf_exception_handler(exc, context)
	#如果响应为空表示不是序列化器异常,补充数据库异常
    if response is None:
        view = context['view']
        if isinstance(exc, DatabaseError) or isinstance(exc, RedisError):
            # 数据库异常
            logger.error('[%s] %s' % (view, exc))
            response = Response({'message': '服务器内部错误'}, status=status.HTTP_507_INSUFFICIENT_STORAGE)

    return response 
开发者ID:xuchaoa,项目名称:CTF_AWD_Platform,代码行数:20,代码来源:exceptions.py

示例4: __call__

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def __call__(self, fn):
        """Function wrapper."""
        @wraps(fn)
        def wrapped_f(*args, **kwargs):
            c = 0
            while c <= self.retry_count:
                try:
                    return fn(*args, **kwargs)
                except RedisError:
                    logging.critical("retrying because of this exception - %s",
                                     c)
                    logging.exception("exception to retry ")
                    if c == self.retry_count:
                        raise
                c += 1

        return wrapped_f 
开发者ID:ybrs,项目名称:pydisque,代码行数:19,代码来源:client.py

示例5: app

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def app():
    app = create_app()
    app.config['PROPAGATE_EXCEPTIONS'] = False

    @app.route('/api/minimal-mode')
    def minimal_mode():
        return unicode(g.auth.is_minimal_mode)

    @app.route('/api/mysql')
    def mysql_error():
        raise SQLAlchemyError()

    @app.route('/api/redis')
    def redis_error():
        raise RedisError()

    return app 
开发者ID:huskar-org,项目名称:huskar,代码行数:19,代码来源:test_db_tester.py

示例6: _bulk_execute

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def _bulk_execute(self, node, keys, command, args=()):
        pipeline = node.client.pipeline(transaction=False)
        retry = 0
        command_pcs = [command, None]
        command_pcs.extend(args)
        while retry < self.RETRY_COUNT:
            for key in keys:
                command_pcs[1] = key
                pipeline.execute_command(*command_pcs)
            try:
                values = pipeline.execute(raise_on_error=False)
                return zip(keys, values)
            except exceptions.RedisError:
                LOG.exception('Error executing pipeline at retry %d', retry)
                retry += 1
        return False 
开发者ID:openstack,项目名称:dragonflow,代码行数:18,代码来源:redis_db_driver.py

示例7: _scan

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def _scan(self, table, key=None, topic=None):
        (pattern, nodes) = self._query_info(table, topic, key)
        keys = set()

        for node in nodes:
            retry = 0
            while retry < self.RETRY_COUNT:
                LOG.debug('Getting all keys with pattern %s retry %d',
                          pattern, retry)
                try:
                    node_keys = self._get_all_keys_from_node(node, pattern)
                    keys.update(node_keys)
                    break
                except exceptions.RedisError:
                    LOG.exception('Error getting keys from node %s:%s',
                                  node.ip, node.port)
                    retry += 1
                    self._cluster.populate_cluster()
            if retry == self.RETRY_COUNT:
                raise df_exceptions.DBKeyNotFound('ALL KEYS')
        return keys 
开发者ID:openstack,项目名称:dragonflow,代码行数:23,代码来源:redis_db_driver.py

示例8: lock

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def lock(self, resource, ttl):
        retry = 0
        val = self.get_unique_id()

        # Add 2 milliseconds to the drift to account for Redis expires
        # precision, which is 1 millisecond, plus 1 millisecond min
        # drift for small TTLs.
        drift = int(ttl * self.clock_drift_factor) + 2

        redis_errors = list()
        while retry < self.retry_count:
            n = 0
            start_time = int(time.time() * 1000)
            del redis_errors[:]
            for server in self.servers:
                try:
                    if self.lock_instance(server, resource, val, ttl):
                        n += 1
                except RedisError as e:
                    redis_errors.append(e)
            elapsed_time = int(time.time() * 1000) - start_time
            validity = int(ttl - elapsed_time - drift)
            if validity > 0 and n >= self.quorum:
                if redis_errors:
                    raise MultipleRedlockException(redis_errors)
                return Lock(validity, resource, val)
            else:
                for server in self.servers:
                    try:
                        self.unlock_instance(server, resource, val)
                    except:
                        pass
                retry += 1
                time.sleep(self.retry_delay)
        return False 
开发者ID:SPSCommerce,项目名称:redlock-py,代码行数:37,代码来源:__init__.py

示例9: unlock

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def unlock(self, lock):
        redis_errors = []
        for server in self.servers:
            try:
                self.unlock_instance(server, lock.resource, lock.key)
            except RedisError as e:
                redis_errors.append(e)
        if redis_errors:
            raise MultipleRedlockException(redis_errors) 
开发者ID:SPSCommerce,项目名称:redlock-py,代码行数:11,代码来源:__init__.py

示例10: test_ignore_event_on_get_task_registry_error

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def test_ignore_event_on_get_task_registry_error(self, mock_redis_get):
        """Check if an event is ignored when a TaskRegistryError is thrown"""

        mock_redis_get.side_effect = RedisError

        self.task_scheduler.registry.add('mytask', 'git', 'commit', {})

        handler = StartedJobHandler(self.task_scheduler)
        result = JobResult(0, 1, 'mytask', 'git', 'commit')
        event = JobEvent(JobEventType.STARTED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, False) 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:15,代码来源:test_scheduler.py

示例11: test_ignore_event_on_update_task_registry_error

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def test_ignore_event_on_update_task_registry_error(self, mock_redis_exists):
        """Check if an event is ignored when a TaskRegistryError is thrown"""

        mock_redis_exists.side_effect = [False, True, RedisError]

        self.task_scheduler.registry.add('mytask', 'git', 'commit', {})

        handler = StartedJobHandler(self.task_scheduler)
        result = JobResult(0, 1, 'mytask', 'git', 'commit')
        event = JobEvent(JobEventType.STARTED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, False) 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:15,代码来源:test_scheduler.py

示例12: test_ignore_event_on_task_registry_error

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def test_ignore_event_on_task_registry_error(self, mock_redis_get):
        """Check if an event is ignored when a TaskRegistryError is thrown"""

        mock_redis_get.side_effect = RedisError

        self.task_scheduler.registry.add('mytask', 'git', 'commit', {})

        handler = CompletedJobHandler(self.task_scheduler)
        result = JobResult(0, 1, 'mytask', 'git', 'commit')
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, False) 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:15,代码来源:test_scheduler.py

示例13: remove

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def remove(self, task_id):
        """Remove a task from the registry.

        To remove it, pass its identifier with `task_id` parameter.
        When the identifier is not found, a `NotFoundError` exception
        is raised.

        :param task_id: identifier of the task to remove

        :raises NotFoundError: raised when the given task identifier
            is not found in the registry
        :raises TaskRegistryError: raised when the given task identifier
            is not removed from the registry
        """
        self._rwlock.writer_acquire()
        try:
            task_key = self._task_key(task_id)
            found = self.conn.exists(task_key)

            if not found:
                raise NotFoundError(element=str(task_id))

            self.conn.delete(task_key)

            logger.debug("Task %s removed from the registry", str(task_id))
        except RedisError as e:
            msg = "Task {} not removed: {}".format(task_id, e)
            logger.error(msg)
            raise TaskRegistryError(cause=msg)
        finally:
            self._rwlock.writer_release() 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:33,代码来源:tasks.py

示例14: update

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def update(self, task_id, task):
        """Update a task in the registry.

        Update a task stored in the registry using its task identifier. When
        the task does not exist, a `NotFoundError` exception will be
        raised.

        :param task_id: task identifier
        :param task: task object

        :returns: a task object

        :raises TaskRegistryError: raised when the task is not
            updated
        """
        self._rwlock.writer_acquire()
        try:
            task_key = self._task_key(task_id)
            found = self.conn.exists(task_key)

            if not found:
                logger.warning("Task %s not found, adding it", str(task_id))

            self.conn.set(task_key, pickle.dumps(task))

            logger.debug("Task %s updated", str(task_id))
        except RedisError as e:
            msg = "Task {} not updated: {}".format(task_id, e)
            logger.error(msg)
            raise TaskRegistryError(cause=msg)
        finally:
            self._rwlock.writer_release() 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:34,代码来源:tasks.py

示例15: tasks

# 需要导入模块: from redis import exceptions [as 别名]
# 或者: from redis.exceptions import RedisError [as 别名]
def tasks(self):
        """Get the list of tasks

        Retrieve the list of tasks stored in the registry

        :returns: a list of tasks

        :raises TaskRegistryError: raised when the tasks cannot
            be listed
        """
        self._rwlock.reader_acquire()
        try:
            tasks = []
            keys = []

            match_prefix = "{}*".format(TASK_PREFIX)
            total, found = self.conn.scan(match=match_prefix)
            keys.extend([f.decode("utf-8") for f in found])
            while total != 0:
                total, found = self.conn.scan(cursor=total, match=match_prefix)
                keys.extend([f.decode("utf-8") for f in found])

            keys.sort()
            for k in keys:
                task_dump = self.conn.get(k)
                tasks.append(pickle.loads(task_dump))

            return tasks
        except RedisError as e:
            msg = "Tasks not listed: {}".format(e)
            logger.error(msg)
            raise TaskRegistryError(cause=msg)
        finally:
            self._rwlock.reader_release() 
开发者ID:chaoss,项目名称:grimoirelab-kingarthur,代码行数:36,代码来源:tasks.py


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