本文整理汇总了Python中libmc.Client.append方法的典型用法代码示例。如果您正苦于以下问题:Python Client.append方法的具体用法?Python Client.append怎么用?Python Client.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SingleServerCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import append [as 别名]
#.........这里部分代码省略.........
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)
assert mc.get(key_xl) == val
def test_noreply(self):
mc = self.noreply_mc
assert mc.set('foo', 'bar')
assert mc.touch('foo', 30)
v, ck = mc.gets('foo')
assert mc.cas('foo', 'bar2', 0, ck)
mc.delete('foo')
assert mc.set('foo', 1024)
assert mc.incr('foo', 1) is None
assert mc.get('foo') == 1025
assert mc.decr('foo', 3) is None
assert mc.get('foo') == 1022
def test_injection(self):
# credit to The New Page of Injections Book:
# Memcached Injections @ blackhat2014 [pdf](http://t.cn/RP0J10Z)
mc = self.mc
assert mc.delete('injected')
assert mc.set('a' * 250, 'biu')
assert not mc.set('a' * 251, 'biu')
mc.set('a' * 251, 'set injected 0 3600 10\r\n1234567890')
assert mc.get('injected') is None
mc.delete('injected')
mc.set('key1', '1234567890')
mc.set('key1 0', '123456789012345678901234567890\r\n'
'set injected 0 3600 3\r\nINJ\r\n')
assert mc.get('injected') is None
def test_maxiov(self):
key_tmpl = 'not_existed.%s'
assert self.mc.get_multi([key_tmpl % i for i in range(10000)]) == {}
def test_get_set_raw(self):
self.mc.set('foo', 233)
assert self.mc.get_raw('foo') == ('233', 2)
self.mc.set_raw('foo', '2335', 0, 2)
assert self.mc.get('foo') == 2335
def test_stats(self):
stats = self.mc.stats()
for addr, dct in stats.iteritems():
assert isinstance(dct['version'], str)
assert (isinstance(dct['rusage_system'], float) or
isinstance(dct['rusage_user'], float))
assert isinstance(dct['curr_connections'], int)
def test_get_set_large_raw(self):
key = 'large_raw_key'
key_dup = '%s_dup' % key
val = 'i' * int(_DOUBAN_CHUNK_SIZE * 1.5)
for mc in (self.mc, self.compressed_mc):
mc.set(key, val)
assert mc.get(key) == val
raw_val1, flags1 = mc.get_raw(key)
assert mc.set_raw(key_dup, raw_val1, 0, flags1)
assert mc.get_raw(key) == mc.get_raw(key_dup)
def test_patch_no_compress(self):
key = 'no_compress'
val = '1024'
self.mc.set(key, val, compress=False)
large_patch = 'hahahaha' * 512
self.mc.prepend(key, large_patch)
assert self.mc.get(key) == large_patch + val
self.mc.delete(key)
self.mc.set(key, val, compress=False)
large_patch = 'hahahaha' * 512
self.mc.append(key, large_patch)
assert self.mc.get(key) == val + large_patch
self.mc.delete(key)
示例2: CmemcachedRegressionCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import append [as 别名]
class CmemcachedRegressionCase(unittest.TestCase):
def setUp(self):
host = "127.0.0.1"
port = 21211
self.server_addr = '%s:%d' % (host, port)
self.mc = Client([self.server_addr], comp_threshold=1024)
if cmemcached is not None:
self.old_mc = cmemcached.Client([self.server_addr],
comp_threshold=1024)
def test_set_get(self):
self.mc.set("key", "value")
self.assertEqual(self.mc.get("key"), "value")
self.mc.set("key_int", 1)
self.assertEqual(self.mc.get("key_int"), True)
self.mc.set("key_long", int(1234567890))
self.assertEqual(self.mc.get("key_long"), int(1234567890))
self.mc.set("key_object", BigObject())
self.assertEqual(self.mc.get("key_object"), BigObject())
big_object = BigObject('x', 1000001)
self.mc.set("key_big_object", big_object)
self.assertEqual(self.mc.get("key_big_object"), big_object)
def test_set_get_none(self):
self.assertEqual(self.mc.set('key', None), True)
self.assertEqual(self.mc.get('key'), None)
def test_chinese_set_get(self):
key = '豆瓣'
value = '在炎热的夏天我们无法停止上豆瓣'
self.assertEqual(self.mc.set(key, value), True)
self.assertEqual(self.mc.get(key), value)
def test_unicode_set_get(self):
key = "test_unicode_set_get"
value = u"中文"
self.assertEqual(self.mc.set(key, value), True)
self.assertEqual(self.mc.get(key), value)
def test_special_key(self):
key = 'keke a kid'
value = 1024
self.assertEqual(self.mc.set(key, value), False)
self.assertEqual(self.mc.get(key), None)
key = 'u:keke a kid'
self.assertEqual(self.mc.set(key, value), False)
self.assertEqual(self.mc.get(key), None)
def test_unicode_key(self):
key1 = u"answer"
key2 = u"答案"
bytes_key1 = "answer"
bytes_key2 = "答案"
value = 42
self.assertEqual(self.mc.set(key1, value), True)
self.assertEqual(self.mc.get(key1), value)
self.assertEqual(self.mc.set(key2, value), True)
self.assertEqual(self.mc.get(key2), value)
self.assertEqual(self.mc.incr(key2), value + 1)
self.assertEqual(self.mc.get(key2), value + 1)
self.assertEqual(self.mc.delete(key1), True)
self.assertEqual(self.mc.get(key1), None)
self.assertEqual(self.mc.add(key1, value), True)
self.assertEqual(self.mc.get(key1), value)
self.assertEqual(self.mc.add(key1, value), False)
self.assertEqual(self.mc.set(key1, value), True)
self.assertEqual(self.mc.get(bytes_key1), self.mc.get(key1))
self.assertEqual(self.mc.get(bytes_key2), self.mc.get(key2))
def test_add(self):
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"
#.........这里部分代码省略.........