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


Python Client.set_multi方法代碼示例

本文整理匯總了Python中libmc.Client.set_multi方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.set_multi方法的具體用法?Python Client.set_multi怎麽用?Python Client.set_multi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在libmc.Client的用法示例。


在下文中一共展示了Client.set_multi方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import set_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
開發者ID:txdywy,項目名稱:libmc,代碼行數:10,代碼來源:infinite_set_get.py

示例2: main

# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import set_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
開發者ID:601186678,項目名稱:libmc,代碼行數:12,代碼來源:infinite_set_get.py

示例3: CmemcachedRegressionCase

# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import set_multi [as 別名]

#.........這裏部分代碼省略.........
        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"
        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)
開發者ID:douban,項目名稱:libmc,代碼行數:70,代碼來源:test_cmemcached_regression.py


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