示例#1
0
 def txn():
     index = random.randint(1, config.num_shards)
     shard_name = name + str(index)
     counter = Shard.get_by_key_name(shard_name)
     if counter is None:
         counter = Shard(key_name=shard_name, name=name)
     counter.count += delta
     counter.put()
示例#2
0
def get_count(name):
    """
    Retrieve the value for a given sharded counter.
    """
    total = memcache.get(name)
    if total is None:
        total = 0
        for counter in Shard.all().filter('name = ', name):
            total += counter.count
        memcache.add(name, str(total), 60)
    return total