Exemplo n.º 1
0
 def txn():
     index = random.randint(0, CounterController.NUM_SHARDS - 1)
     shard_name = name + str(index)
     counter = GCounter.get_by_key_name(shard_name)
     if counter is None:
         counter = GCounter(key_name=shard_name, name=name)
     counter.count += 1
     counter.put()
Exemplo n.º 2
0
    def get_count(name):
        """Retrieve the value for a given sharded counter.

        Parameters:
          name - The name of the counter
        """
        total = memcache.get(name)
        if total is None:
            total = 0
            for counter in GCounter.all().filter('name = ', name):
                total += counter.count
            memcache.add(name, total, 60)
        return total