def disLike(self, userId, entityType, entityId): redis = RedisSet() getKey = RedisKeyutil() # 在该对象的喜欢集合中去除该用户 likeKey = getKey.getLikeKey(entityType, entityId) redis.srem(likeKey, userId) # 在该对象的不喜欢的集合中增加该用户 dislikekey = getKey.getDisLikeKey(entityType, entityId) redis.sadd(dislikekey, userId) return redis.scard(likeKey)
def getLikeStatus(self, userId, entityType, entityId): redis = RedisSet() getKey = RedisKeyutil() likeKey = getKey.getLikeKey(entityType, entityId) dislikekey = getKey.getDisLikeKey(entityType, entityId) # 喜欢1 不喜欢-1 无所谓0 if redis.sismember(likeKey, userId): return "1" elif redis.sismember(dislikekey, userId): return "-1" else: return 0
def getRankInfluencesKey(self,rankType,rankId): return RedisKeyutil().getRankInfluencesKey(rankType,rankId)
def getRankKey(self,rankType): return RedisKeyutil().getRankKey(rankType)
def getLikecount(self, entityType, entityId): redis = RedisSet() getKey = RedisKeyutil() likeKey = getKey.getLikeKey(entityType, entityId) return redis.scard(likeKey)
# -*- coding: utf-8 -*- from __future__ import unicode_literals from RedisOps import RedisSet, RedisKeyutil, RedisZset import datetime RedisKeyutil = RedisKeyutil() class FollowService(object): """关注通用服务""" def __init__(self): super(FollowService, self).__init__() def follow(self, entityType, entityId, userId, userType='3'): # 实体的粉丝列表 followerKey = RedisKeyutil.getFollowerKey(entityType, entityId) print "followerKey:%s enType:%s enId:%s uId:%s uType:%s" % ( followerKey, entityType, entityId, userId, userType) # 用户的关注列表,定义userType:3 followeeKey = RedisKeyutil.getFolloweeKey(userType, userId) print "followeeKey:%s enType:%s enId:%s uId:%s uType:%s" % ( followeeKey, entityType, entityId, userId, userType) date = int(datetime.date.today().strftime("%Y%m%d")) # import pdb; pdb.set_trace() try: split = "_" instance = entityType + split + entityId rz = RedisZset() rz.zadd(followerKey, date, userId) rz.zadd(followeeKey, date, instance)