コード例 #1
0
ファイル: stats.py プロジェクト: therewillbecode/ichnaea
    def update_key(self, stat_key, day):
        # determine the value from the day before
        query = self.session.query(Stat).filter(Stat.key == stat_key).filter(Stat.time < day).order_by(Stat.time.desc())
        before = query.first()
        old_value = 0
        if before:
            old_value = before.value

        # get the value from redis for the day in question
        stat_counter = StatCounter(stat_key, day)
        value = stat_counter.get(self.redis_client)

        # insert or update a new stat value
        hashkey = Stat.to_hashkey(key=stat_key, time=day)
        Stat.incr(self.session, hashkey, value, old=old_value)

        # queue the redis value to be decreased
        stat_counter.decr(self.pipe, value)
コード例 #2
0
 def add_counter(self, stat_key, time, value):
     stat_counter = StatCounter(stat_key, time)
     with redis_pipeline(self.redis_client) as pipe:
         stat_counter.incr(pipe, value)