本文整理汇总了Python中pymemcache.client.hash.HashClient.flush_all方法的典型用法代码示例。如果您正苦于以下问题:Python HashClient.flush_all方法的具体用法?Python HashClient.flush_all怎么用?Python HashClient.flush_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymemcache.client.hash.HashClient
的用法示例。
在下文中一共展示了HashClient.flush_all方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemcacheService
# 需要导入模块: from pymemcache.client.hash import HashClient [as 别名]
# 或者: from pymemcache.client.hash.HashClient import flush_all [as 别名]
#.........这里部分代码省略.........
flags = request.initial_flags()
if request.direction() == MemcacheIncrementRequest.INCREMENT:
updated_val = request.initial_value() + request.delta()
else:
updated_val = request.initial_value() - request.delta()
updated_val = max(updated_val, 0) % (MAX_INCR + 1)
try:
response = self._memcache.add(
encoded_key, (six.binary_type(updated_val), flags))
except (TRANSIENT_ERRORS + (MemcacheClientError,)):
raise apiproxy_errors.ApplicationError(
UNSPECIFIED_ERROR, 'Unable to set initial value')
if response is False:
raise apiproxy_errors.ApplicationError(
UNSPECIFIED_ERROR, 'Unable to set initial value')
return updated_val
def _Dynamic_Increment(self, request, response):
"""Implementation of increment for memcache.
Args:
request: A MemcacheIncrementRequest protocol buffer.
response: A MemcacheIncrementResponse protocol buffer.
"""
new_value = self._Increment(request.name_space(), request)
response.set_new_value(new_value)
def _Dynamic_BatchIncrement(self, request, response):
"""Implementation of batch increment for memcache.
Args:
request: A MemcacheBatchIncrementRequest protocol buffer.
response: A MemcacheBatchIncrementResponse protocol buffer.
"""
for request_item in request.item_list():
item = response.add_item()
try:
new_value = self._Increment(request.name_space(), request_item)
except apiproxy_errors.ApplicationError as error:
if error.application_error == INVALID_VALUE:
item.set_increment_status(MemcacheIncrementResponse.NOT_CHANGED)
else:
item.set_increment_status(MemcacheIncrementResponse.ERROR)
continue
item.set_increment_status(MemcacheIncrementResponse.OK)
item.set_new_value(new_value)
def _Dynamic_FlushAll(self, request, response):
"""Implementation of MemcacheService::FlushAll().
Args:
request: A MemcacheFlushRequest.
response: A MemcacheFlushResponse.
"""
# TODO: Prevent a project from clearing another project's namespace.
self._memcache.flush_all()
def _Dynamic_Stats(self, request, response):
"""Implementation of MemcacheService::Stats().
Args:
request: A MemcacheStatsRequest.
response: A MemcacheStatsResponse.
"""
# TODO: Gather stats for a project rather than the deployment.
hits = 0
misses = 0
byte_hits = 0
items = 0
byte_count = 0
oldest_item_age = 0
for server in six.itervalues(self._memcache.clients):
server_stats = server.stats()
hits += server_stats.get('get_hits', 0)
misses += server_stats.get('get_misses', 0)
byte_hits += server_stats.get('bytes_read', 0)
items += server_stats.get('curr_items', 0)
byte_count += server_stats.get('bytes', 0)
# Using the "age" field may not be correct here. The GAE docs claim this
# should specify "how long in seconds since the oldest item in the cache
# was accessed" rather than when it was created.
item_stats = server.stats('items')
oldest_server_item = max(age for key, age in six.iteritems(item_stats)
if key.endswith(':age'))
oldest_item_age = max(oldest_item_age, oldest_server_item)
stats = response.mutable_stats()
stats.set_hits(hits)
stats.set_misses(misses)
stats.set_byte_hits(byte_hits)
stats.set_items(items)
stats.set_bytes(byte_count)
stats.set_oldest_item_age(oldest_item_age)