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)
def check_stat(self, stat_key, time, value): hashkey = Stat.to_hashkey(key=stat_key, time=time) stat = Stat.getkey(self.session, hashkey) self.assertEqual(stat.value, value)