4 changed files with 106 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||
|
package com.bnyer.common.core.utils; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/9/17 15:53 |
||||
|
*/ |
||||
|
|
||||
|
public class RedisKeyUtil { |
||||
|
|
||||
|
private static final String SPLIT = ":"; |
||||
|
private static final String PREFIX_FOLLOWEE = "followee"; |
||||
|
private static final String PREFIX_FOLLOWER = "follower"; |
||||
|
|
||||
|
|
||||
|
//某个用户关注的实体(键:用户Id,值:实体Id)
|
||||
|
//followee:【userId:entityType】->zset(entityId,now)
|
||||
|
public static String getFolloweeKey(Long userId, Long creatorId,String platform) { |
||||
|
return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + creatorId + SPLIT + platform; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//某个实体拥有的粉丝(键:实体Id,值:用户Id)
|
||||
|
//follower:【entityType:entityId】->zset(userId,now)
|
||||
|
public static String getFollowerKey(Long userId, Long creatorId,String platform) { |
||||
|
return PREFIX_FOLLOWER + SPLIT + creatorId + SPLIT + userId + SPLIT + platform; |
||||
|
} |
||||
|
//entityType不可以删除,userId和entityId值会有重复,需要借助entityType构成键的一部分加以区分,【不对】
|
||||
|
//entityType不可以删除,Id值相同的情况下,需要借助entityType以示区分
|
||||
|
|
||||
|
} |
||||
|
|
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.bnyer.img.service; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/9/17 15:54 |
||||
|
*/ |
||||
|
public interface FollowService { |
||||
|
|
||||
|
/** |
||||
|
* 关注艺术家 |
||||
|
* @param userId 用户id |
||||
|
* @param creatorId 艺术家id |
||||
|
* @param platform 平台 |
||||
|
*/ |
||||
|
void follow(Long userId,Long creatorId,String platform); |
||||
|
|
||||
|
/** |
||||
|
* 取消关注 |
||||
|
* @param userId 用户id |
||||
|
* @param creatorId 艺术家id |
||||
|
* @param platform 平台 |
||||
|
*/ |
||||
|
void unFollow(Long userId,Long creatorId,String platform); |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
package com.bnyer.img.service.impl; |
||||
|
|
||||
|
import com.bnyer.common.core.utils.RedisKeyUtil; |
||||
|
import com.bnyer.common.redis.service.RedisService; |
||||
|
import com.bnyer.img.service.FollowService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/9/17 16:18 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class FollowServiceImpl implements FollowService { |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisService redisService; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisTemplate redisTemplate; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void follow(Long userId, Long creatorId, String platform) { |
||||
|
//关注键
|
||||
|
String followeeKey = RedisKeyUtil.getFolloweeKey(userId, creatorId, platform); |
||||
|
//粉丝键
|
||||
|
String followerKey = RedisKeyUtil.getFollowerKey(userId, creatorId, platform); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void unFollow(Long userId, Long creatorId, String platform) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue