本文整理汇总了Python中libmc.Client.flush_all方法的典型用法代码示例。如果您正苦于以下问题:Python Client.flush_all方法的具体用法?Python Client.flush_all怎么用?Python Client.flush_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.flush_all方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Memcached
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import flush_all [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)