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 unfollow(self, entityType, entityId, userId, userType='3'): followerKey = RedisKeyutil.getFollowerKey(entityType, entityId) followeeKey = RedisKeyutil.getFolloweeKey(userType, userId) # import pdb; pdb.set_trace() try: split = "_" instance = entityType + split + entityId rz = RedisZset() rz.zrem(followerKey, userId) rz.zrem(followeeKey, instance) return True except Exception as e: print e return False
def getFollowees(self, entityType, entityId, offset, count): followeeKey = RedisKeyutil.getFolloweeKey(entityType, entityId) print "getFollowees--followeeKey:", followeeKey try: rz = RedisZset() return rz.zrevrange(followeeKey, offset, count) except Exception as e: print e return False
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) return True except Exception as e: print e return False
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)
def isFollower(self, entityType, entityId, userId): followerKey = RedisKeyutil.getFollowerKey(entityType, entityId) rz = RedisZset() return rz.zscore(followerKey, userId) != None
def getFolloweesCount(self, entityType, entityId): followeeKey = RedisKeyutil.getFollowerKey(entityType, entityId) rz = RedisZset() return rz.zcard(followeeKey)
# -*- 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)