Python redis.ResponseError() Examples

The following are 10 code examples of redis.ResponseError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module redis , or try the search function .
Example #1
Source File: redis_store.py    From plaso with Apache License 2.0 6 votes vote down vote up
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)) 
Example #2
Source File: test_commands.py    From redisbloom-py with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #3
Source File: manage.py    From ruskit with MIT License 6 votes vote down vote up
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() 
Example #4
Source File: test.py    From redisearch-py with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example #5
Source File: rediscache.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #6
Source File: test_redis_scripts.py    From tasktiger with MIT License 5 votes vote down vote up
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 
Example #7
Source File: query_result.py    From redisgraph-py with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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. 
Example #8
Source File: manage.py    From ruskit with MIT License 5 votes vote down vote up
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() 
Example #9
Source File: test.py    From redisearch-py with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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() 
Example #10
Source File: list.py    From pottery with Apache License 2.0 5 votes vote down vote up
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