當前位置: 首頁>>代碼示例>>Python>>正文


Python HashClient.flush_all方法代碼示例

本文整理匯總了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)
開發者ID:obino,項目名稱:appscale,代碼行數:104,代碼來源:memcache_distributed.py


注:本文中的pymemcache.client.hash.HashClient.flush_all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。