当前位置: 首页>>代码示例>>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;未经允许,请勿转载。