示例#1
0
    def user_sub_obj_ids(cls, uid, page, pagesize, maxs):
        skey = UserSubShow.SUB_SHOW_IDS % {'uid': uid}
        gkey = UserSubGame.SUB_GAME_IDS % {'uid': uid}
        key = cls.USER_SUB_IDS % {'uid': uid}

        if not Redis.exists(skey):
            UserSubShow._load_sub_show_ids(uid)
        if not Redis.exists(gkey):
            UserSubGame._load_sub_game_ids(uid)

        # 始终合并以保证实时性
        Redis.delete(key)
        all_keys = list()
        for k in [skey, gkey]:
            try:
                count = Redis.zcard(k)
            except exceptions.ResponseError:
                count = 0
            count and all_keys.append(k)
        all_keys and Redis.zunionstore(key, all_keys)

        try:
            if maxs:
                ids = Redis.zrevrangebyscore(key, '(%.6f' % (maxs), '-inf', start=0, num=pagesize, withscores=True)
            else:
                start = (page - 1) * pagesize
                stop = start + pagesize - 1
                ids = Redis.zrevrange(key, start, stop, withscores=True)
        except exceptions.ResponseError:
            ids = []
        return list(ids)
示例#2
0
 def sub_game_count(cls, uid):
     key = cls.SUB_GAME_IDS % ({'uid': uid})
     if not Redis.exists(key):
         cls._load_sub_game_ids(uid)
     try:
         count = Redis.zcard(key)
     except exceptions.ResponseError:
         count = 0
     return count
示例#3
0
 def video_comment_count(cls, activity_id):
     key = cls.ACTIVITY_COMMENT_IDS % ({'aid': activity_id})
     if not Redis.exists(key):
         cls._load_video_comment_ids(activity_id)
     try:
         count = Redis.zcard(key)
     except exceptions.ResponseError:
         count = 0
     return count
示例#4
0
 def video_comment_count(cls, video_id):
     key = cls.VIDEO_COMMENT_IDS % ({'vid': video_id})
     if not Redis.exists(key):
         cls._load_video_comment_ids(video_id)
     try:
         count = Redis.zcard(key)
     except exceptions.ResponseError:
         count = 0
     return count