def increment(self, key, participant_identifier, count=1): if count == 0: return cache_key = COUNTER_CACHE_KEY % key freq_cache_key = COUNTER_FREQ_CACHE_KEY % key new_value = Count.next( cache_key, participant_identifier, count) if new_value > count: Count.next( freq_cache_key, new_value - count, -1 ) Count.next( freq_cache_key, new_value, 1)
def clear(self, key, participant_identifier): try: # Remove the direct entry cache_key = COUNTER_CACHE_KEY % key freq = Count.get(cache_key, participant_identifier) Count.deletefield(cache_key, participant_identifier) # Remove from the histogram freq_cache_key = COUNTER_FREQ_CACHE_KEY % key Count.next(freq_cache_key, freq, -1) except: # Handle Redis failures gracefully pass