diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/RedisKeyUtil.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/RedisKeyUtil.java new file mode 100644 index 0000000..707b1d9 --- /dev/null +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/RedisKeyUtil.java @@ -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以示区分 + +} + diff --git a/bnyer-common/bnyer-common-redis/src/main/java/com/bnyer/common/redis/service/RedisService.java b/bnyer-common/bnyer-common-redis/src/main/java/com/bnyer/common/redis/service/RedisService.java index c05f630..76a47e4 100644 --- a/bnyer-common/bnyer-common-redis/src/main/java/com/bnyer/common/redis/service/RedisService.java +++ b/bnyer-common/bnyer-common-redis/src/main/java/com/bnyer/common/redis/service/RedisService.java @@ -3,6 +3,8 @@ package com.bnyer.common.redis.service; import java.time.Duration; import java.util.*; import java.util.concurrent.TimeUnit; + +import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.script.DefaultRedisScript; @@ -167,6 +169,18 @@ public class RedisService return setOperation; } + public void zSetCacheObject(final String redisKey, final T value, double score){ + redisTemplate.opsForZSet().add(redisKey, value, score); + } + + public void zSetRemove(final String redisKey, T value) { + redisTemplate.opsForZSet().remove(redisKey, value); + } + + public long zCardGet(final String redisKey){ + return redisTemplate.opsForZSet().zCard(redisKey); + } + /** * 获得缓存的set * diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FollowService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FollowService.java new file mode 100644 index 0000000..b933f7a --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FollowService.java @@ -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); +} diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FollowServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FollowServiceImpl.java new file mode 100644 index 0000000..dc28119 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FollowServiceImpl.java @@ -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) { + + } +}