|
@@ -1,73 +0,0 @@
|
|
|
-package com.chelvc.framework.redis.cache.impl;
|
|
|
-
|
|
|
-
|
|
|
-import com.chelvc.framework.redis.cache.Cache;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.data.redis.core.ZSetOperations;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-/**
|
|
|
- * redis 缓存实现
|
|
|
- *
|
|
|
- * @author 七仔
|
|
|
- * @date 2023/7/11
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class RedisCache implements Cache {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<Object, Object> redisTemplate;
|
|
|
-
|
|
|
- public RedisCache() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void incrementScore(String sortedSetName, String keyword, Integer score) {
|
|
|
- redisTemplate.opsForZSet().incrementScore(sortedSetName, keyword, score);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * zrevrange命令, 查询Sorted Set中指定范围的值
|
|
|
- * 返回的有序集合中,score大的在前面
|
|
|
- * zrevrange方法无需担心用于指定范围的start和end出现越界报错问题
|
|
|
- *
|
|
|
- * @param sortedSetName sortedSetName
|
|
|
- * @param start 查询范围开始位置
|
|
|
- * @param end 查询范围结束位置
|
|
|
- * @return 符合排序的集合
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer start, Integer end) {
|
|
|
- return this.redisTemplate.opsForZSet().reverseRangeWithScores(sortedSetName, start, end);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * zrevrange命令, 查询Sorted Set中指定范围的值
|
|
|
- * 返回的有序集合中,score大的在前面
|
|
|
- * zrevrange方法无需担心用于指定范围的start和end出现越界报错问题
|
|
|
- *
|
|
|
- * @param sortedSetName sortedSetName
|
|
|
- * @param number 获取数量
|
|
|
- * @return 符合排序的集合
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer number) {
|
|
|
- return this.redisTemplate.opsForZSet().reverseRangeWithScores(sortedSetName, 0, number);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 移除 Zset队列值
|
|
|
- *
|
|
|
- * @param key key值
|
|
|
- * @param value 删除的集合
|
|
|
- * @return 删除数量
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Long zRemove(String key, String... value) {
|
|
|
- return redisTemplate.opsForZSet().remove(key, value);
|
|
|
- }
|
|
|
-}
|