當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.incr方法代碼示例

本文整理匯總了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"
#.........這裏部分代碼省略.........
開發者ID:douban,項目名稱:libmc,代碼行數:103,代碼來源:test_cmemcached_regression.py


注:本文中的libmc.Client.incr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。