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


Python redis.ResponseError方法代碼示例

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


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

示例1: _SetClientName

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def _SetClientName(cls, redis_client, name):
    """Attempts to sets a Redis client name.

    This method ignores errors from the Redis server or exceptions
    indicating the method is missing, as setting the name is not a critical
    function, and it is not currently supported by the fakeredis test library.

    Args:
      redis_client (Redis): an open Redis client.
      name (str): name to set.
    """
    try:
      redis_client.client_setname(name)
    except redis.ResponseError as exception:
      logger.debug(
          'Unable to set redis client name: {0:s} with error: {1!s}'.format(
              name, exception)) 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:19,代碼來源:redis_store.py

示例2: testCFAddInsert

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def testCFAddInsert(self):
        self.assertTrue(rb.cfCreate('cuckoo', 1000))
        self.assertTrue(rb.cfAdd('cuckoo', 'filter'))
        self.assertFalse(rb.cfAddNX('cuckoo', 'filter'))
        self.assertEqual(1, rb.cfAddNX('cuckoo', 'newItem'))
        self.assertEqual([1], rb.cfInsert('captest', ['foo']))
        self.assertEqual([1], rb.cfInsert('captest', ['foo'], capacity=1000))
        self.assertEqual([1], rb.cfInsertNX('captest', ['bar']))
        self.assertEqual([1], rb.cfInsertNX('captest', ['food'], nocreate='1'))
        self.assertEqual([0, 0, 1], rb.cfInsertNX('captest', ['foo', 'bar', 'baz']))
        self.assertEqual([0], rb.cfInsertNX('captest', ['bar'], capacity=1000))
        self.assertEqual([1], rb.cfInsert('empty1', ['foo'], capacity=1000))
        self.assertEqual([1], rb.cfInsertNX('empty2', ['bar'], capacity=1000))
        self.assertRaises(ResponseError, run_func(rb.cfInsert, 'noexist', ['foo']))
        info = rb.cfInfo('captest')
        self.assertEqual(5, info.insertedNum)
        self.assertEqual(0, info.deletedNum)
        self.assertEqual(1, info.filterNum) 
開發者ID:RedisBloom,項目名稱:redisbloom-py,代碼行數:20,代碼來源:test_commands.py

示例3: migrate

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def migrate(ctx, args):
    src = ClusterNode.from_uri(args.src)
    cluster = Cluster.from_node(src)

    if args.dst:
        dst = ClusterNode.from_uri(args.dst)

    if args.dst and args.slot is not None:
        try:
            cluster.migrate_slot(src, dst, args.slot, verbose=True)
        except redis.ResponseError as e:
            ctx.abort(str(e))
    elif args.dst:
        count = len(src.slots) if args.count is None else args.count
        cluster.migrate(src, dst, count)
    else:
        cluster.migrate_node(src, args.count, income=args.income)

    cluster.wait() 
開發者ID:eleme,項目名稱:ruskit,代碼行數:21,代碼來源:manage.py

示例4: testNoCreate

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def testNoCreate(self):
        client = self.getCleanClient('idx')
        client.create_index((TextField('f1'), TextField('f2'), TextField('f3')))

        client.add_document('doc1', f1='f1_val', f2='f2_val')
        client.add_document('doc2', f1='f1_val', f2='f2_val')

        client.add_document('doc1', f3='f3_val', no_create=True)
        client.add_document('doc2', f3='f3_val', no_create=True, partial=True)

        for i in self.retry_with_reload():
            # Search for f3 value. All documents should have it
            res = client.search('@f3:f3_val')
            self.assertEqual(2, res.total)

            # Only the document updated with PARTIAL should still have the f1 and f2
            # values
            res = client.search('@f3:f3_val @f2:f2_val @f1:f1_val')
            self.assertEqual(1, res.total)            
            
        with self.assertRaises(redis.ResponseError) as error:
            client.add_document('doc3', f2='f2_val', f3='f3_val', no_create=True) 
開發者ID:RediSearch,項目名稱:redisearch-py,代碼行數:24,代碼來源:test.py

示例5: incr

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def incr(self, key, delta=1, version=None):
        """
        Add delta to value in the cache. If the key does not exist, raise a
        ValueError exception.
        """
        key = self.make_key(key, version=version)
        exists = self._client.exists(key)
        if not exists:
            raise ValueError("Key '%s' not found" % key)
        try:
            value = self._client.incr(key, delta)
        except redis.ResponseError:
            value = self.get(key) + delta
            self.set(key, value)
        return value 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:17,代碼來源:rediscache.py

示例6: test_execute_pipeline_2

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def test_execute_pipeline_2(self):
        p = self.conn.pipeline()
        p.set('x', 1)
        # Test that invalid operation halts pipeline.
        p.lrange('x', 0, -1)
        p.set('y', 1)
        pytest.raises(redis.ResponseError, self.scripts.execute_pipeline, p)
        assert self.conn.get('x') == '1'
        assert self.conn.get('y') is None 
開發者ID:closeio,項目名稱:tasktiger,代碼行數:11,代碼來源:test_redis_scripts.py

示例7: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def __init__(self, graph, response):
        self.graph = graph
        self.header = []
        self.result_set = []

        # If we encountered a run-time error, the last response element will be an exception.
        if isinstance(response[-1], ResponseError):
            raise response[-1]

        if len(response) is 1:
            self.parse_statistics(response[0])
        else:
            self.parse_results(response)
            self.parse_statistics(response[-1])  # Last element. 
開發者ID:RedisGraph,項目名稱:redisgraph-py,代碼行數:16,代碼來源:query_result.py

示例8: replicate

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def replicate(ctx, args):
    """Make node to be the slave of a master.
    """
    slave = ClusterNode.from_uri(args.node)
    master = ClusterNode.from_uri(args.master)
    if not master.is_master():
        ctx.abort("Node {!r} is not a master.".format(args.master))

    try:
        slave.replicate(master.name)
    except redis.ResponseError as e:
        ctx.abort(str(e))

    Cluster.from_node(master).wait() 
開發者ID:eleme,項目名稱:ruskit,代碼行數:16,代碼來源:manage.py

示例9: createIndex

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def createIndex(self, client, num_docs = 100):

        assert isinstance(client, Client)
        #conn.flushdb()
        #client = Client('test', port=conn.port)
        try:
            client.create_index((TextField('play', weight=5.0), 
                                TextField('txt'), 
                                NumericField('chapter')))
        except redis.ResponseError:
            client.drop_index()
            return self.createIndex(client, num_docs=num_docs)

        chapters = {}
        bzfp = bz2.BZ2File(WILL_PLAY_TEXT)
        if six.PY3:
            bzfp = TextIOWrapper(bz2.BZ2File(WILL_PLAY_TEXT), encoding='utf8')

        r = csv.reader(bzfp, delimiter=';')
        for n, line in enumerate(r):
            #['62816', 'Merchant of Venice', '9', '3.2.74', 'PORTIA', "I'll begin it,--Ding, dong, bell."]

            play, chapter, character, text = line[1], line[2], line[4], line[5]

            key = '{}:{}'.format(play, chapter).lower()
            d = chapters.setdefault(key, {})
            d['play'] = play
            d['txt'] = d.get('txt', '') + ' ' + text
            d['chapter'] = int(chapter or 0)
            if len(chapters) == num_docs:
                break

        indexer = client.batch_indexer(chunk_size=50)
        self.assertIsInstance(indexer, Client.BatchIndexer)
        self.assertEqual(50, indexer.chunk_size)

        for key, doc in six.iteritems(chapters):
            indexer.add_document(key, **doc)
        indexer.commit() 
開發者ID:RediSearch,項目名稱:redisearch-py,代碼行數:41,代碼來源:test.py

示例10: _raise_on_error

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import ResponseError [as 別名]
def _raise_on_error(func):
        @functools.wraps(func)
        def wrap(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except ResponseError:
                raise IndexError('list assignment index out of range')
        return wrap 
開發者ID:brainix,項目名稱:pottery,代碼行數:10,代碼來源:list.py


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