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


Python Client.get_stats方法代碼示例

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


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

示例1: Memcached

# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import get_stats [as 別名]
class Memcached(object):
    def __init__(self, servers):
        """Initialize memcached.
        @param servers: an array of servers. Servers can be passed in two forms:
            1. Strings of the form host:port (implies a default weight of 1).
            2. Tuples of the form (host:port, weight) (weight as integer)
        """
        if LIBMC:
            self._client = Client(servers, comp_threshold=10240, noreply=True)
        else:
            self._client = Client(servers)
        self.timeout = 0

    def reset(self):
        self._client.flush_all()

    def size(self):
        bytes = 0
        stats = self._client.get_stats()
        for name, stat in stats:
            bytes += int(stat["bytes"])
        return bytes

    def keys(self):
        raise MemcachedException(
            "It's not possible to fetch keys from memcached"
        )

    def values(self):
        raise MemcachedException(
            "It's not possible to fetch values from memcached"
        )

    def get(self, key, default=None):
        value = self._client.get(key)
        if value is not None:
            return value
        return default

    def __getitem__(self, key):
        return self._client.get(key)

    def __setitem__(self, key, object):
        if PYLIBMC and not LIBMC:
            self._client.set(
                key,
                object,
                time=self.timeout,
                min_compress_len=1024000,
                compress_level=zlib.Z_BEST_SPEED,
            )
        else:
            self._client.set(key, object, time=self.timeout)

    def __delitem__(self, key):
        self._client.delete(key)
開發者ID:bluedynamics,項目名稱:bda.cache,代碼行數:58,代碼來源:memcached.py


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