本文整理匯總了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)