Пример #1
0
    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)
Пример #2
0
    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
Пример #3
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
Пример #4
0
 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
Пример #5
0
    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
Пример #6
0
	def  getRankInfluencesKey(self,rankType,rankId):
		return RedisKeyutil().getRankInfluencesKey(rankType,rankId)
Пример #7
0
	def getRankKey(self,rankType):
		return RedisKeyutil().getRankKey(rankType)
Пример #8
0
    def getLikecount(self, entityType, entityId):
        redis = RedisSet()
        getKey = RedisKeyutil()
        likeKey = getKey.getLikeKey(entityType, entityId)

        return redis.scard(likeKey)
Пример #9
0
 def isFollower(self, entityType, entityId, userId):
     followerKey = RedisKeyutil.getFollowerKey(entityType, entityId)
     rz = RedisZset()
     return rz.zscore(followerKey, userId) != None
Пример #10
0
 def getFolloweesCount(self, entityType, entityId):
     followeeKey = RedisKeyutil.getFollowerKey(entityType, entityId)
     rz = RedisZset()
     return rz.zcard(followeeKey)
Пример #11
0
# -*- 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)