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


Python Client.stats方法代碼示例

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


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

示例1: SingleServerCase

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

示例2: CmemcachedRegressionCase

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

#.........這裏部分代碼省略.........
    def test_marshal(self):
        v = [{2: {"a": 337}}]
        self.mc.set("a", v)
        self.assertEqual(self.mc.get("a"), v)
        # TODO
        '''
        raw, flags = self.mc.get_raw("a")
        self.assertEqual(raw, marshal.dumps(v, 2))
        '''

    def test_big_list(self):
        v = range(1024 * 1024)
        r = self.mc.set('big_list', v)

        self.assertEqual(r, True)
        self.assertEqual(self.mc.get('big_list'), v)

    def test_touch(self):
        self.mc.set('test', True)
        self.assertEqual(self.mc.get('test'), True)
        self.assertEqual(self.mc.touch('test', -1), True)
        self.assertEqual(self.mc.get('test'), None)

        self.mc.set('test', True)
        self.assertEqual(self.mc.get('test'), True)
        self.assertEqual(self.mc.touch('test', 1), True)
        time.sleep(1)
        self.assertEqual(self.mc.get('test'), None)

    def test_client_pickable(self):
        import pickle
        d = pickle.dumps(self.mc)
        self.mc = pickle.loads(d)
        self.test_stats()

    def test_stats(self):
        s = self.mc.stats()
        self.assertEqual(self.server_addr in s, True)
        st = s[self.server_addr]
        st_keys = {
            "pid",
            "uptime",
            "time",
            "version",
            "pointer_size",
            "rusage_user",
            "rusage_system",
            "curr_items",
            "total_items",
            "bytes",
            "curr_connections",
            "total_connections",
            "connection_structures",
            "cmd_get",
            "cmd_set",
            "get_hits",
            "get_misses",
            "evictions",
            "bytes_read",
            "bytes_written",
            "limit_maxbytes",
            "threads",
        }
        self.assertTrue(set(st.keys()) >= st_keys)
        ''' TODO
        mc = cmemcached.Client([INVALID_SERVER_ADDR, self.server_addr])
開發者ID:douban,項目名稱:libmc,代碼行數:70,代碼來源:test_cmemcached_regression.py


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