本文整理汇总了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))
示例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)
示例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()
示例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)
示例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
示例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
示例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.
示例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()
示例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()
示例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