def is_star_by_id_list(cls, user_id, li, cid=0): if user_id: key = R_STAR_BY_USER_ID_CID % (user_id, int(cid)) with redis.pipeline() as p: for i in li: p.zscore(key, i) return p.execute() else: return [0] * len(li)
def id_by_sso_id(id): _id = redis.hget(R_ID_BY_SSO_ID, id) if not _id: _id = gid() with redis.pipeline() as p: p.hset(R_ID_BY_SSO_ID, id, _id) p.hset(R_SSO_ID_BY_ID, _id, id) p.execute() return int(_id)
def is_star_by_id_list(cls, user_id, li, cid=0): if user_id: key = R_STAR_BY_USER_ID_CID%(user_id, int(cid)) with redis.pipeline() as p: for i in li: p.zscore(key, i) return p.execute() else: return [0]*len(li)
def rm(cls, user_id, id, cid): key = R_STAR_BY_USER_ID_CID % (user_id, 0) if redis.zrank(key, id) is not None: with redis.pipeline() as p: p.hincrby(R_STAR_COUNT, user_id, -1) p.hincrby(R_STAR_COUNT, id, -1) p.zrem(key, id) p.zrem(R_STAR_BY_USER_ID_CID % (user_id, cid), id) p.zrem(R_STAR_BY_ID % id, user_id) p.execute()
def rm(cls, user_id, id, cid): key = R_STAR_BY_USER_ID_CID % (user_id, 0) if redis.zrank(key, id) is not None: with redis.pipeline() as p: p.hincrby(R_STAR_COUNT, user_id, -1) p.hincrby(R_STAR_COUNT, id, -1) p.zrem(key, id) p.zrem(R_STAR_BY_USER_ID_CID%(user_id, cid), id) p.zrem(R_STAR_BY_ID % id, user_id) p.execute()
def new(cls, user_id, id, cid): key = R_STAR_BY_USER_ID_CID % (user_id, 0) if redis.zrank(key, id) is None: _now = int(time()) with redis.pipeline() as p: p.hincrby(R_STAR_COUNT, user_id) p.hincrby(R_STAR_COUNT, id) p.zadd(key, _now, id) p.zadd(R_STAR_BY_USER_ID_CID % (user_id, cid), _now, id) p.zadd(R_STAR_BY_ID % id, time(), user_id) p.execute()
def new(cls, user_id, id, cid): key = R_STAR_BY_USER_ID_CID % (user_id, 0) if redis.zrank(key, id) is None: _now = int(time()) with redis.pipeline() as p: p.hincrby(R_STAR_COUNT, user_id) p.hincrby(R_STAR_COUNT, id) p.zadd(key, _now, id) p.zadd(R_STAR_BY_USER_ID_CID%(user_id, cid), _now, id) p.zadd(R_STAR_BY_ID % id, time(), user_id) p.execute()