Esempio n. 1
0
 def incr_key(stat_key, amount):
     try:
         total = rdb.incr(stat_key, amount)
     except redis.exceptions.ResponseError:
         rdb.delete(stat_key)
         total = rdb.incr(stat_key, amount)
     return total
Esempio n. 2
0
 def clear_mc(target, amount):
     post_id = target.post_id
     tag_name = Tag.get(target.tag_id).name
     for ident in (post_id, tag_name):
         total = int(PostTag.get_count_by_tag(ident))
         rdb.incr(MC_KEY_POST_STATS_BY_TAG % ident, amount)
         pages = math.ceil((max(total, 0) or 1) / PER_PAGE)
         for p in range(1, pages + 1):
             rdb.delete(MC_KEY_POSTS_BY_TAG % (ident, p))
Esempio n. 3
0
 def clear_mc(target, amount):
     tag_name = Tag.get(target.tag_id).name
     stat_key = MC_KEY_POST_STATS_BY_TAG % tag_name
     total = int(PostTag.get_count_by_tag(tag_name))
     try:
         rdb.incr(stat_key, amount)
     except redis.exceptions.ResponseError:
         rdb.delete(stat_key)
         rdb.incr(stat_key, amount)
     pages = math.ceil((max(total, 0) or 1) / PER_PAGE)
     for p in range(1, pages + 1):
         rdb.delete(MC_KEY_POSTS_BY_TAG % (tag_name, p))
Esempio n. 4
0
 def clear_mc(target, amount):
     post_id = target.post_id
     tag_name = Tag.get(target.tag_id).name
     for ident in (post_id, tag_name):
         total = int(PostTag.get_count_by_tag(ident))
         try:
             rdb.incr(MC_KEY_POST_COUNT_BY_TAG.format(ident), amount)
         except redis.exceptions.ResponseError:
             rdb.delete(MC_KEY_POST_COUNT_BY_TAG.format(ident))
             rdb.incr(MC_KEY_POST_COUNT_BY_TAG.format(ident), amount)
         pages = math.ceil((max(total, 0) or 1) / PER_PAGE)
         for p in range(1, pages + 1):
             rdb.delete(MC_KEY_POSTS_BY_TAG.format(ident, p))