def create(cls, **query): inst = super(UserGiftLog, cls).create(**query) if inst: if inst.gift_from == const.FROM_RECORD: key = VIDEO_GIFT_KEY % (inst.from_id) try: if Redis.exists(key) and query.get("send_success"): Redis.zadd(key, util.datetime2timestamp(inst.create_at), cjson.dumps(inst, 2)) except exceptions.ResponseError: Redis.delete(key) key = TOP_SENDER_KEY % (inst.user_id) try: if Redis.exists(key) and query.get("send_success"): Redis.zincrby(key, inst.gold_price, inst.from_user) except exceptions.ResponseError: Redis.delete(key) if inst.gift_from == const.FROM_LIVE: key = USER_TOTAL_GOLD % ({'uid': inst.user_id}) Redis.delete(key) return inst
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)
def is_followed(cls, uid, sid): key = cls.SUB_SHOW_IDS % {'uid': uid} if not Redis.exists(key): cls._load_sub_show_ids(uid) if not Redis.exists(key): return False try: followed = Redis.zrank(key, str(sid)) except exceptions.ResponseError: followed = None return followed is not None
def get_limit_config(cls, report_type): key = cls.REPORT_CONFIG % {'rtype': report_type} if not Redis.exists(key): cfg = cls.collection.find_one({'report_type': report_type}) _id = cfg and str(cfg['_id']) Redis.set(key, _id, 86400) return Redis.get(key)
def get_used_today(cls, aid): today = datetime.date.today().strftime('%y%m%d') key = cls.USED_TODAY % ({'day': today, 'aid': aid}) if not Redis.exists(key): Redis.set(key, 0) Redis.expire(key, 60 * 60 * 24) return int(Redis.get(key))
def get_user_live_history(cls, uid): today = datetime.date.today().strftime('%y%m%d') key = cls.USER_LIVE_DAILY_HISTORY % {'today': today, 'uid': uid} if not Redis.exists(key): cls._load_user_live_history(uid, key) logs = Redis.get(key) history = cjson.loads(logs) if logs else [] return history
def get_banner_bottom_photo(cls): key = cls.BOTTOM_PHOTO if not Redis.exists(key): cls._load_banner_bottom_photo() try: bids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: bids = [] return list(bids)
def all_ids_by_os(cls, os): key = cls.ALL_IDS % ({'os': os}) if not Redis.exists(key): cls._load_ids_by_os(os, key) try: _ids = Redis.get(key) except exceptions.ResponseError: _ids = [] return cjson.loads(_ids)
def get_banner_title_color(cls): key = cls.TITLE_COLOR if not Redis.exists(key): cls._load_banner_title_color() try: tids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: tids = [] return list(tids)
def all_ad_ids(cls): key = cls.ALL_AD_IDS if not Redis.exists(key): cls._load_all_ad_ids() try: ad_ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: ad_ids = [] return list(ad_ids)
def recommend_sub_ids(cls): key = cls.GAME_RECOMMEND_SUBSCRIBE if not Redis.exists(key): cls._load_recommend_sub_ids() try: gids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: gids = [] return list(gids)
def all_channels_ids(cls): key = cls.ALL_CHANNELS_IDS if not Redis.exists(key): cls._load_all_channels_ids() try: _ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: _ids = [] return list(_ids)
def all_module_ids(cls): key = cls.ALL_MODULE_IDS if not Redis.exists(key): cls._load_all_module_ids() try: mids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: mids = [] return list(mids)
def user_red_packets(cls, uid): key = cls.USER_REDPACKET_IDS % ({'uid': uid}) if not Redis.exists(key): cls._load_user_redpackets(uid) try: ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: ids = [] return list(ids)
def all_hot_words(cls): key = cls.ALL_HOT_WORDS if not Redis.exists(key): cls._load_all_hot_words() try: _ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: _ids = [] return list(_ids)
def get_live_tids(cls): key = cls.LIVE_TASKS if not Redis.exists(key): cls._load_live_tasks() try: ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: ids = [] return list(ids)
def all_ids(cls): key = cls.ALL_IDS if not Redis.exists(key): cls._load_live_redpackets() try: ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: ids = [] return list(ids)
def get_history_live(cls, uid): key = cls.USER_HISTORY_LIVE % {'uid': uid} if not Redis.exists(key): cls._load_history_live(uid, key) try: _ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: _ids = [] return list(_ids)
def get_user_gift_code_ids(cls, uid): key = USER_GIFT_CODE_KEY % {'uid': uid} if not Redis.exists(key): cls._load_user_gift_code_ids(uid) try: ids = Redis.lrange(key, 0, -1) except: ids = [] return ids
def hot_game_ids(cls): key = cls.HOT_GAME_IDS if not Redis.exists(key): cls._load_hot_game_ids() try: gids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: gids = [] return list(gids)
def all_category_ids(cls): key = cls.ALL_CATEGORYS_IDS if not Redis.exists(key): cls._load_all_category_ids() try: cate_ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: cate_ids = [] return list(cate_ids)
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
def category_object_ids(cls, cate_id): key = cls.CATEGORY_OBJ_IDS % ({'cate_id': cate_id}) if not Redis.exists(key): cls._load_category_object_ids(cate_id) try: cate_ids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: cate_ids = [] return list(cate_ids)
def activity_status(cls, aid): key = cls.ACTIVITY_CONFIG % ({'aid': str(aid)}) if not Redis.exists(key): cls._load_activity_status(aid, key) try: activity_status = Redis.get(key) except exceptions.ResponseError: activity_status = 'begin' return activity_status
def all_module_game_ids(cls, module_id): key = cls.ALL_MODULE_GAME_IDS.format(module_id=module_id) if not Redis.exists(key): cls._load_all_module_game_ids(module_id) try: mids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: mids = [] return list(mids)
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
def all_banner_ids(cls): key = cls.ALL_BANNER_IDS if not Redis.exists(key): cls._load_all_banner_ids() try: bids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: bids = [] return list(bids)
def vip_giftcode_ids(cls, vid): key = cls.ALL_IDS % ({'vid': vid}) if not Redis.exists(key): cls._load_giftcode_ids(vid) try: gids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: gids = [] return list(gids)
def all_banners_by_version(cls): key = cls.ALL_BANNERS_BY_VERSION if not Redis.exists(key): cls._load_all_banner_version() try: bids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: bids = [] return list(bids)
def category_game_ids(cls, cid): key = cls.CATEGORY_GAME_IDS % ({'cid': cid}) if not Redis.exists(key): cls._load_category_game_ids(cid) try: gids = Redis.lrange(key, 0, -1) except exceptions.ResponseError: gids = [] return list(gids)