本文整理汇总了Python中memcache.Client.get_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_stats方法的具体用法?Python Client.get_stats怎么用?Python Client.get_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memcache.Client
的用法示例。
在下文中一共展示了Client.get_stats方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemcacheStore
# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import get_stats [as 别名]
class MemcacheStore(DictProxy):
def __init__(self, host, port):
from memcache import Client
self.mc= Client(['%s:%s' % (host, port)])
def update(self, updates):
for update in updates:
(processId, data)= update
self.mc.set(processId, data)
def get(self, processId, default= None):
data= self.mc.get(processId)
if data == None:
return default
return data
def pop(self, processId):
data= self.mc.get(processId)
self.mc.delete(processId)
return data
if data == None:
return default
def __len__(self):
return int(self.mc.get_stats()[0][1].get('curr_items'))
示例2: preset
# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import get_stats [as 别名]
def preset(sample):
global addresses
conn = Client([gethostname()+':11211'])
if conn.get_stats()[0][1]['curr_items'] == 0:
for k in addresses:
conn.set(addr_prefix+k, 0)
示例3: MemcacheBackend
# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import get_stats [as 别名]
class MemcacheBackend(StorageBackend):
def __init__(self, options, args):
if not options.servers:
raise Exception("memcache servers are required")
self.servers = options.servers.split(",")
self.open()
@classmethod
def parse_arguments(cls, optparse):
optparse.add_option(
"-m",
"--servers",
dest="servers",
help="comma-separated list of memcached servers",
metavar="SERVERS",
default="localhost:11211",
)
def _encode_key(self, key):
return key.encode("base64").rstrip("\n")
def _decode_key(self, key):
return key.decode("base64")
def _get(self, key, default=None):
return self.mc.get(self._encode_key(key))
def _get_multi(self, keys):
keys = map(self._encode_key, keys)
ret = self.mc.get_multi(keys)
return dict((self._decode_key(key), value) for (key, value) in ret.iteritems())
def _put(self, key, val):
return self.mc.set(self._encode_key(key), val)
def _put_multi(self, keys):
keys = dict((self._encode_key(key), value) for (key, value) in keys.iteritems())
self.mc.set_multi(keys)
def _delete(self, key):
self.mc.delete(self._encode_key(key))
def close(self):
if getattr(self, "mc", None):
self.mc.disconnect_all()
self.mc = None
def open(self):
self.close()
self.mc = MemcacheClient(self.servers)
def stats(self):
return dict(self.mc.get_stats())
示例4: MemcacheCli
# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import get_stats [as 别名]
class MemcacheCli(cmd.Cmd, object):
def __init__(self, host_list):
super(MemcacheCli, self).__init__()
self.memcache = Client(host_list) # Use our memcache library to initiate a connection
self._check_connection(host_list) # Make sure we actually have connections, since our library doesn't make this apparent
self.prompt = '(memcache) '
# Time for some hardcore introspection and dynamic method creation
for name in dir(self.memcache):
# List our methods, ignoring private methods and ones that should be hidden to our CLI
if not name.startswith('_') and not self._is_hidden(name):
attr = getattr(self.memcache, name)
if callable(attr):
# Make sure we only keep callable methods, let's pin the doc strings to them while we are at it
setattr(self.__class__, 'do_' + name, self._make_cmd(name))
doc = (getattr(attr, '__doc__') or '').strip()
if doc: # Not everything has a docstring
setattr(self.__class__, 'help_' + name, self._make_help(doc))
@staticmethod
def _make_cmd(name):
# Whats a little functional passing between friends?
# This is our core factory for creating dynamic methods
def _get_stats(self, line):
try:
pp = pprint.PrettyPrinter(depth=4)
pp.pprint(self.memcache.get_stats(line))
except Exception, e:
print_error(e)
def handler(self, line):
parts = line.split()
try:
# This is where the magic happens, get our function by name, pass the arguments, then pretty-print the results
pprint.pprint(getattr(self.memcache, name)(*parts))
except Exception, e:
print_error(e)