本文整理汇总了Python中libmc.Client.get_multi方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_multi方法的具体用法?Python Client.get_multi怎么用?Python Client.get_multi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.get_multi方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
def main():
mc = Client(["127.0.0.1:%d" % (21211 + i) for i in range(10)])
dct = {"test_key_%d" % i: "i" * 1000 for i in range(10)}
while True:
print "%.2f: set_multi: %r" % (time.time(), mc.set_multi(dct))
print "%.2f: get_multi: %r" % (time.time(), mc.get_multi(dct.keys()) == dct)
time.sleep(0.5)
print
示例2: main
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
def main():
mc = Client(['127.0.0.1:%d' % (21211 + i) for i in range(10)])
dct = {'test_key_%d' % i: 'i' * 1000 for i in range(10)}
while True:
print '%.2f: set_multi: %r' % (time.time(), mc.set_multi(dct))
print '%.2f: get_multi: %r' % (
time.time(), mc.get_multi(dct.keys()) == dct
)
time.sleep(0.5)
print
示例3: MCStore
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
class MCStore(object):
def __init__(self, server):
self.server = server
self.mc = Client([server], do_split=0)
def __del__(self):
self.close()
def __repr__(self):
return '<MCStore(server=%s)>' % repr(self.server)
def __str__(self):
return self.server
def set(self, key, data, rev=0):
return bool(self.mc.set(key, data, rev))
def set_raw(self, key, data, rev=0, flag=0): # interface for sync data
if rev < 0:
raise str(rev)
return self.mc.set_raw(key, data, rev, flag)
def get(self, key):
try:
r = self.mc.get(key)
if r is None and self.mc.get_last_error() != 0:
raise IOError(self.mc.get_last_error())
return r
except ValueError:
self.mc.delete(key)
def get_raw(self, key):
r, flag = self.mc.get_raw(key)
if r is None and self.mc.get_last_error() != 0:
raise IOError(
self.mc.get_last_error(), self.mc.get_last_strerror())
return r, flag
def get_multi(self, keys):
return self.mc.get_multi(keys)
def delete(self, key):
return bool(self.mc.delete(key))
def close(self):
if self.mc is not None:
self.mc = None
示例4: SingleServerCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
class SingleServerCase(unittest.TestCase):
def setUp(self):
self.mc = Client(["127.0.0.1:21211"])
self.compressed_mc = Client(["127.0.0.1:21211"], comp_threshold=1024)
self.noreply_mc = Client(["127.0.0.1:21211"], noreply=True)
def test_attribute(self):
"Test attributes are accessible from Python code"
mc = self.mc
assert hasattr(mc, 'comp_threshold')
assert hasattr(mc, 'servers')
def test_misc(self):
mc = self.mc
mc.get_multi(['foo', 'tuiche'])
mc.delete('foo')
mc.delete('tuiche')
assert mc.get('foo') is None
assert mc.get('tuiche') is None
mc.set('foo', 'biu')
mc.set('tuiche', 'bb')
assert mc.get('foo') == 'biu'
assert mc.get('tuiche') == 'bb'
assert (mc.get_multi(['foo', 'tuiche']) ==
{'foo': 'biu', 'tuiche': 'bb'})
mc.set_multi({'foo': 1024, 'tuiche': '8964'})
assert (mc.get_multi(['foo', 'tuiche']) ==
{'foo': 1024, 'tuiche': '8964'})
def test_delete(self):
mc = self.mc
assert mc.set('smmf', 0xCA909) is True
assert mc.get('smmf') == 0xCA909
assert mc.delete('smmf') is True
assert mc.delete_multi(['smmf']) is True
assert mc.set('smmf', 0xCA909) is True
assert mc.delete_multi(['smmf']) is True
assert mc.delete('smmf') is True
assert mc.delete('smmf') is True
def test_incr_decr(self):
mc = self.mc
mc.set('wazi', 99)
assert mc.incr('wazi', 1) == 100
assert mc.decr('wazi', 1) == 99
mc.delete('wazi')
assert mc.incr('wazi', 1) is None
assert mc.decr('wazi', 1) is None
def test_cas(self):
mc = self.mc
mc.delete('bilinda')
k1 = 'bilinda'
v1 = 'butchers'
assert mc.gets(k1) is None
mc.set(k1, v1)
v1_, ck = mc.gets('bilinda')
v2 = 'ding'
assert v1 == v1_
assert mc.cas(k1, v2, 0, ck) is True
assert mc.cas(k1, v1, 0, ck) is not True
v2_, ck = mc.gets('bilinda')
assert v2 == v2_
def test_large(self):
mc = self.mc
BUF_500KB = 'i' * (500 * 1000)
BUF_1MB = 'i' * (1000 * 1000)
key_500kb = 'test_500kb'
key_1mb = 'test_1mb'
mc.delete(key_500kb)
mc.delete(key_1mb)
mc.set(key_500kb, BUF_500KB)
assert mc.get(key_500kb) == BUF_500KB
mc.set(key_1mb, BUF_1MB)
assert mc.get(key_1mb) == BUF_1MB
mc.delete(key_500kb)
mc.delete(key_1mb)
dct = {key_500kb: BUF_500KB, key_1mb: BUF_1MB}
mc.set_multi(dct)
assert mc.get_multi(dct.keys()) == dct
def test_extra_large(self):
threshold = 1000000
mc = self.mc
key_xl = 'test_very_large'
val = 'i' * threshold
assert mc.set(key_xl, val)
assert mc.get(key_xl) == val
val += 'b'
assert mc.set(key_xl, val)
assert mc.get(key_xl) == val
val = 'i' * (threshold + threshold)
assert mc.set(key_xl, val)
assert mc.get(key_xl) == val
val += 'b'
assert mc.set(key_xl, val)
#.........这里部分代码省略.........
示例5: CmemcachedRegressionCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
#.........这里部分代码省略.........
key = 'test_add'
self.mc.delete(key)
self.assertEqual(self.mc.add(key, 'tt'), True)
self.assertEqual(self.mc.get(key), 'tt')
self.assertEqual(self.mc.add(key, 'tt'), 0)
self.mc.delete(key + '2')
self.assertEqual(self.mc.add(key + '2', range(10)), True)
def test_replace(self):
key = 'test_replace'
self.mc.delete(key)
self.assertEqual(self.mc.replace(key, ''), 0)
self.assertEqual(self.mc.set(key, 'b'), True)
self.assertEqual(self.mc.replace(key, 'a'), True)
self.assertEqual(self.mc.get(key), 'a')
def test_append(self):
key = "test_append"
value = b"append\n"
self.mc.delete(key)
self.assertEqual(self.mc.append(key, value), 0)
self.mc.set(key, b"")
self.assertEqual(self.mc.append(key, value), True)
self.assertEqual(self.mc.append(key, value), True)
self.assertEqual(self.mc.prepend(key, b'before\n'), True)
self.assertEqual(self.mc.get(key), b'before\n' + value * 2)
def test_set_multi(self):
values = dict(('key%s' % k, ('value%s' % k) * 100)
for k in range(1000))
values.update({' ': ''})
self.assertEqual(self.mc.set_multi(values), False)
del values[' ']
self.assertEqual(self.mc.get_multi(list(values.keys())), values)
def test_append_large(self):
k = 'test_append_large'
self.mc.set(k, b'a' * 2048)
self.mc.append(k, b'bbbb')
assert b'bbbb' not in self.mc.get(k)
self.mc.set(k, b'a' * 2048, compress=False)
self.mc.append(k, b'bbbb')
assert b'bbbb' in self.mc.get(k)
def test_incr(self):
key = "Not_Exist"
self.assertEqual(self.mc.incr(key), None)
# key="incr:key1"
# self.mc.set(key, "not_numerical")
# self.assertEqual(self.mc.incr(key), 0)
key = "incr:key2"
self.mc.set(key, 2007)
self.assertEqual(self.mc.incr(key), 2008)
def test_decr(self):
key = "Not_Exist"
self.assertEqual(self.mc.decr(key), None)
# key="decr:key1"
# self.mc.set(key, "not_numerical")
# self.assertEqual(self.mc.decr(key),0)
key = "decr:key2"
self.mc.set(key, 2009)
self.assertEqual(self.mc.decr(key), 2008)
def test_get_multi(self):
keys = ["hello1", "hello2", "hello3"]
示例6: CmemcachedRegressionPrefixCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_multi [as 别名]
class CmemcachedRegressionPrefixCase(unittest.TestCase):
def setUp(self):
host = "127.0.0.1"
port = 21211
self.prefix = '/prefix'
self.server_addr = '%s:%d' % (host, port)
self.prefixed_mc = Client([self.server_addr], comp_threshold=1024,
prefix=self.prefix)
self.mc = Client([self.server_addr], comp_threshold=1024)
def test_duplicate_prefix_text(self):
for case in ['%sforever/young', 'forever%s/young', 'forever/young/%s']:
nasty_key = case % self.prefix
self.prefixed_mc.set(nasty_key, 1)
self.assertEqual(self.prefixed_mc.get(nasty_key), 1)
self.assertEqual(self.prefixed_mc.get_multi([nasty_key]),
{nasty_key: 1})
def test_misc(self):
raw_mc = self.mc
prefixed_mc = self.prefixed_mc
raw_mc.delete('a')
prefixed_mc.set('a', 1)
assert(prefixed_mc.get('a') == 1)
assert(raw_mc.get(self.prefix + 'a') == 1)
assert(raw_mc.get('a') is None)
prefixed_mc.add('b', 2)
assert(prefixed_mc.get('b') == 2)
assert(raw_mc.get(self.prefix + 'b') == 2)
assert(raw_mc.get('b') is None)
prefixed_mc.incr('b')
assert(prefixed_mc.get('b') == 3)
assert(raw_mc.get(self.prefix + 'b') == 3)
raw_mc.decr(self.prefix + 'b')
assert(prefixed_mc.get('b') == 2)
prefixed_mc.set_multi({'x': 'a', 'y': 'b'})
ret = prefixed_mc.get_multi(['x', 'y'])
assert(ret.get('x') == 'a' and ret.get('y') == 'b')
assert(prefixed_mc.delete_multi(['a', 'b', 'x', 'y']))
prefixed_mc.set('?foo', 'bar')
assert prefixed_mc.get('?foo') == 'bar'
assert prefixed_mc.get_multi(['?foo']) == {'?foo': 'bar'}
assert raw_mc.get('?%sfoo' % self.prefix) == 'bar'
prefixed_mc.set_multi({'?bar': 'foo'})
assert prefixed_mc.get('?bar') == 'foo'
assert raw_mc.get('?%sbar' % self.prefix) == 'foo'
assert raw_mc.get_list(['?%sbar' % self.prefix]) == ['foo']
def test_ketama(self):
mc = Client(
['localhost', 'myhost:11211', '127.0.0.1:11212', 'myhost:11213'])
rs = {
'test:10000': 'localhost:11211',
'test:20000': '127.0.0.1:11212',
'test:30000': '127.0.0.1:11212',
'test:40000': '127.0.0.1:11212',
'test:50000': '127.0.0.1:11212',
'test:60000': 'myhost:11213',
'test:70000': '127.0.0.1:11212',
'test:80000': '127.0.0.1:11212',
'test:90000': '127.0.0.1:11212',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_ketama_with_jocky_alias(self):
mc = Client([
'localhost localhost',
'myhost:11211 myhost',
'127.0.0.1:11212 127.0.0.1:11212',
'myhost:11213 myhost:11213'
])
rs = {
'test:10000': 'localhost',
'test:20000': '127.0.0.1:11212',
'test:30000': '127.0.0.1:11212',
'test:40000': '127.0.0.1:11212',
'test:50000': '127.0.0.1:11212',
'test:60000': 'myhost:11213',
'test:70000': '127.0.0.1:11212',
'test:80000': '127.0.0.1:11212',
'test:90000': '127.0.0.1:11212',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_ketama_with_alias(self):
mc = Client([
'192.168.1.211:11211 tango.mc.douban.com',
'192.168.1.212:11212 uniform.mc.douban.com',
'192.168.1.211:11212 victor.mc.douban.com',
'192.168.1.212:11211 whiskey.mc.douban.com',
#.........这里部分代码省略.........