當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.ResponseError方法代碼示例

本文整理匯總了Python中redis.exceptions.ResponseError方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.ResponseError方法的具體用法?Python exceptions.ResponseError怎麽用?Python exceptions.ResponseError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.exceptions的用法示例。


在下文中一共展示了exceptions.ResponseError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: analyze

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def analyze(self):
        total_keys = self.redis.dbsize()
        used = {}
        info = {}

        try:
            for key, value in self.redis.config_get("*max-*-*").items():
                used[key] = value
        except ResponseError as e:
            self.logger.warning("*max* option skipped: %s", repr(e))

        for key, value in self.redis.info('memory').items():
            info[key] = value

        return {
            "info": info,
            "used": used,
            "totalKeys": total_keys,
            "redisKeySpaceOverhead": dict_overhead(total_keys),
        } 
開發者ID:gamenet,項目名稱:redis-memory-analyzer,代碼行數:22,代碼來源:GlobalKeySpace.py

示例2: resolve_types

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def resolve_types(self, ret):
        if not self.pipeline_mode:
            try:
                key_with_types = msgpack.unpackb(self.resolve_types_script(ret))
            except ResponseError as e:
                if "CROSSSLOT" not in repr(e):
                    raise e
                key_with_types = self.resolve_with_pipe(ret)
                self.pipeline_mode = True
        else:
            key_with_types = self.resolve_with_pipe(ret)

        for i in range(0, len(ret)):
            yield key_with_types[i], ret[i]

        ret.clear() 
開發者ID:gamenet,項目名稱:redis-memory-analyzer,代碼行數:18,代碼來源:scanner.py

示例3: connect_to_redis

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def connect_to_redis(host, port, db=0, password=None, ssl=False):
    """

    :param host:
    :param port:
    :param db:
    :param password:
    :return RmaRedis:
    """
    try:
        redis = RmaRedis(host=host, port=port, db=db, password=password, ssl=ssl)
        if not check_redis_version(redis):
            sys.stderr.write('This script only works with Redis Server version 2.6.x or higher\n')
            sys.exit(-1)
    except ConnectionError as e:
        sys.stderr.write('Could not connect to Redis Server : %s\n' % e)
        sys.exit(-1)
    except ResponseError as e:
        sys.stderr.write('Could not connect to Redis Server : %s\n' % e)
        sys.exit(-1)
    return redis 
開發者ID:gamenet,項目名稱:redis-memory-analyzer,代碼行數:23,代碼來源:application.py

示例4: _test_pause

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def _test_pause(self):
        """ TODO: """
        """Test that a PAUSE message is acknowledged."""
        queuename = "test_show-%s" % self.testID

        test_job = "Jerbs, they are a thing"

        self.client.pause(queuename, kw_in=True)

        try:
            job_id = self.client.add_job(queuename, test_job)
        except ResponseError:
            pass

        # can we add a job again?
        self.client.pause(queuename, kw_none=True)

        job_id = self.client.add_job(queuename, test_job)

        jobs = self.client.get_job([queuename])

        # TODO(canardleteer): add a test of PAUSE SHOW 
開發者ID:ybrs,項目名稱:pydisque,代碼行數:24,代碼來源:test_disque.py

示例5: is_server_new_enough

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def is_server_new_enough(client, min_version,
                         default=False, prior_version=None):
    """Checks if a client is attached to a new enough redis server."""
    if not prior_version:
        try:
            server_info = client.info()
        except redis_exceptions.ResponseError:
            server_info = {}
        version_text = server_info.get('redis_version', '')
    else:
        version_text = prior_version
    version_pieces = []
    for p in version_text.split("."):
        try:
            version_pieces.append(int(p))
        except ValueError:
            break
    if not version_pieces:
        return (default, version_text)
    else:
        version_pieces = tuple(version_pieces)
        return (version_pieces >= min_version, version_text) 
開發者ID:openstack,項目名稱:taskflow,代碼行數:24,代碼來源:redis_utils.py

示例6: test_scripts

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def test_scripts(self):
        con = self.get_client()
        self.assertRaises(ResponseError, con.scriptset,
                          'ket', 'cpu', 'return 1')
        con.scriptset('ket', 'cpu', script)
        con.tensorset('a', (2, 3), dtype='float')
        con.tensorset('b', (2, 3), dtype='float')
        # try with bad arguments:
        self.assertRaises(ResponseError,
                          con.scriptrun, 'ket', 'bar', inputs=['a'], outputs=['c'])
        con.scriptrun('ket', 'bar', inputs=['a', 'b'], outputs=['c'])
        tensor = con.tensorget('c', as_numpy=False)
        self.assertEqual([4, 6], tensor['values'])
        script_det = con.scriptget('ket')
        self.assertTrue(script_det['device'] == 'cpu')
        self.assertTrue(script_det['source'] == script)
        script_det = con.scriptget('ket', meta_only=True)
        self.assertTrue(script_det['device'] == 'cpu')
        self.assertNotIn('source', script_det)
        con.scriptdel('ket')
        self.assertRaises(ResponseError, con.scriptget, 'ket') 
開發者ID:RedisAI,項目名稱:redisai-py,代碼行數:23,代碼來源:test.py

示例7: test_dagrun_without_load_and_persist

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def test_dagrun_without_load_and_persist(self):
        con = self.get_client()

        dag = con.dag(load='wrongkey')
        with self.assertRaises(ResponseError):
            dag.tensorget('wrongkey').run()

        dag = con.dag()
        dag.tensorset('a', [2, 3, 2, 3], shape=(2, 2), dtype='float')
        dag.tensorset('b', [2, 3, 2, 3], shape=(2, 2), dtype='float')
        dag.modelrun("pt_model", ["a", "b"], ["output"])
        dag.tensorget('output')
        result = dag.run()
        expected = ['OK', 'OK', 'OK', np.array([[4., 6.], [4., 6.]], dtype=np.float32)]
        self.assertTrue(np.allclose(expected.pop(), result.pop()))
        self.assertEqual(expected, result) 
開發者ID:RedisAI,項目名稱:redisai-py,代碼行數:18,代碼來源:test.py

示例8: test_routing_client_releases_connection_on_error

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def test_routing_client_releases_connection_on_error(cluster):
    client = cluster.get_routing_client()
    with pytest.raises(ResponseError):
        client.sadd('key')

    host = cluster.get_router().get_host_for_command('sadd', ['key'])
    pool = cluster.get_pool_for_host(host)
    assert len(pool._available_connections) == pool._created_connections 
開發者ID:getsentry,項目名稱:rb,代碼行數:10,代碼來源:test_cluster.py

示例9: test_mapping_client_releases_connection_on_error

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def test_mapping_client_releases_connection_on_error(cluster):
    client = cluster.get_routing_client().get_mapping_client()
    client.sadd('key')
    with pytest.raises(ResponseError):
        client.join()

    host = cluster.get_router().get_host_for_command('sadd', ['key'])
    pool = cluster.get_pool_for_host(host)
    assert len(pool._available_connections) == pool._created_connections 
開發者ID:getsentry,項目名稱:rb,代碼行數:11,代碼來源:test_cluster.py

示例10: test_managed_mapping_client_releases_connection_on_error

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def test_managed_mapping_client_releases_connection_on_error(cluster):
    with pytest.raises(ResponseError):
        with cluster.get_routing_client().map() as client:
            client.sadd('key')

    host = cluster.get_router().get_host_for_command('sadd', ['key'])
    pool = cluster.get_pool_for_host(host)
    assert len(pool._available_connections) == pool._created_connections 
開發者ID:getsentry,項目名稱:rb,代碼行數:10,代碼來源:test_cluster.py

示例11: discover_slaves

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def discover_slaves(self, service_name):
        "Returns a list of alive slaves for service ``service_name``"
        for sentinel in self.sentinels:
            try:
                slaves = sentinel.sentinel_slaves(service_name)
            except (ConnectionError, ResponseError):
                continue
            slaves = self.filter_slaves(slaves)
            if slaves:
                return slaves
        return [] 
開發者ID:leancloud,項目名稱:satori,代碼行數:13,代碼來源:sentinel.py

示例12: get_int_encoded_bytes

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def get_int_encoded_bytes(redis, key_name):
        try:
            num_value = int(redis.get(key_name))
            if num_value < REDIS_SHARED_INTEGERS:
                return 0
            else:
                return size_of_pointer_fn()
        except ValueError:
            pass
        except ResponseError:
            pass
        except TypeError:
            pass

        return size_of_pointer_fn() 
開發者ID:gamenet,項目名稱:redis-memory-analyzer,代碼行數:17,代碼來源:ValueString.py

示例13: create

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def create(self, ensure_keys_exist=True, mkstream=False):
        """
        Create the consumer group and register it with the group's stream keys.

        :param ensure_keys_exist: Ensure that the streams exist before creating
            the consumer group. Streams that do not exist will be created.
        :param mkstream: Use the "MKSTREAM" option to ensure stream exists (may
            require unstable version of Redis).
        """
        if ensure_keys_exist:
            for key in self.keys:
                if not self.database.exists(key):
                    msg_id = self.database.xadd(key, {'': ''}, id=b'0-1')
                    self.database.xdel(key, msg_id)
                elif self.database.type(key) != b'stream':
                    raise ValueError('Consumer group key "%s" exists and is '
                                     'not a stream. To prevent data-loss '
                                     'this key will not be deleted.' % key)

        resp = {}

        # Mapping of key -> last-read message ID.
        for key, value in self.keys.items():
            try:
                resp[key] = self.database.xgroup_create(key, self.name, value,
                                                        mkstream)
            except ResponseError as exc:
                if exception_message(exc).startswith('BUSYGROUP'):
                    resp[key] = False
                else:
                    raise
        return resp 
開發者ID:coleifer,項目名稱:walrus,代碼行數:34,代碼來源:containers.py

示例14: populate_cluster

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def populate_cluster(self):
        for node in self._configured_nodes:
            client = node.client
            try:
                slots = client.execute_command('CLUSTER', 'SLOTS')
            except exceptions.ConnectionError:
                LOG.exception('Error connecting to cluster node %s:%s',
                              node.ip, node.port)
                continue
            except exceptions.ResponseError as e:
                if str(e).find('cluster support disabled') != -1:
                    LOG.info('Using a single non-cluster node %s:%s',
                             node.ip, node.port)
                    self._nodes_by_host = node
                    self._is_cluster = False
                    return
                LOG.exception('Response error from node %s:%s')
                continue
            self._is_cluster = True
            for slot_info in slots:
                (range_begin, range_end, master_info) = slot_info[0:3]
                master = Node(*master_info)
                self._nodes_by_host[master.key] = master
                for slot in range(int(range_begin), int(range_end) + 1):
                    self._nodes_by_slot[slot] = master
            if self.is_cluster_covered():
                self._covered = True
                break
        if not self._covered:
            LOG.error('Redis cluster not covering slot space')
        for node in self._nodes_by_host.values():
            LOG.info('Cluster node: %s:%s', node.ip, node.port) 
開發者ID:openstack,項目名稱:dragonflow,代碼行數:34,代碼來源:redis_db_driver.py

示例15: _key_command

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import ResponseError [as 別名]
def _key_command(self, command, key, *args):
        node = self._cluster.get_node(key)
        ask = False
        retry = 0
        command_pcs = [command, key]
        command_pcs.extend(args)
        while retry < self.RETRY_COUNT:
            LOG.debug('Executing command "%s" (retry %s)', command_pcs, retry)
            if node is None:
                LOG.error('Error finding node for key %s in cluster', key)
                self._cluster.populate_cluster()
            try:
                if ask:
                    node.client.execute_command('ASKING')
                    ask = False
                return node.client.execute_command(*command_pcs)
            except exceptions.ResponseError as e:
                (reason, slot, ip_port) = str(e).split(' ')
                (ip, port) = ip_port.split(':')
                if reason == 'MOVED':
                    self._cluster.populate_cluster()
                    node = self._cluster.get_node(key)
                if reason == 'ASK':
                    node = self._cluster.get_node_by_host(ip, port)
                    ask = True
            except exceptions.ConnectionError as e:
                LOG.exception('Connection to node %s:%s failed, refreshing',
                              node.ip, node.port)
                self._cluster.populate_cluster()
                node = self._cluster.get_node(key)
            retry += 1

        raise df_exceptions.DBKeyNotFound(key=key) 
開發者ID:openstack,項目名稱:dragonflow,代碼行數:35,代碼來源:redis_db_driver.py


注:本文中的redis.exceptions.ResponseError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。