示例#1
0
 def get_frequency(self, key, participant_identifier):
     try:
         cache_key = COUNTER_CACHE_KEY % key
         freq = Count.get(cache_key, participant_identifier)
         return int(freq) if freq else 0
     except :
         return 0
示例#2
0
    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