本文整理汇总了Python中libmc.Client.incr方法的典型用法代码示例。如果您正苦于以下问题:Python Client.incr方法的具体用法?Python Client.incr怎么用?Python Client.incr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.incr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CmemcachedRegressionCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import incr [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"
#.........这里部分代码省略.........