• (十一)admin-boot项目之整合redis


    (十一)整合redis

    项目地址:https://gitee.com/springzb/admin-boot
    如果觉得不错,给个 star

    简介:
    这是一个基础的企业级基础后端脚手架项目,主要由springboot为基础搭建,后期整合一些基础插件例如:redis、xxl-job、flowable、minioio、easyexcel、skyWalking、rabbitmq

    一、maven引入依赖

    
      <dependency>
          <groupId>org.springframework.bootgroupId>
          <artifactId>spring-boot-starter-data-redisartifactId>
      dependency>
      
      <dependency>
          <groupId>org.apache.commonsgroupId>
          <artifactId>commons-pool2artifactId>
      dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    二、新增redis配置内容

    application-dev.yml添加配置文件

    #  redis相关配置
    spring:
      redis:
        host: 81.69.43.78
        database: 0
        port: 6379
        password:
        lettuce:
          pool:
            # 连接池最大连接数,负值表示没有限制
            max-active: 100
            # 连接池最大阻塞等待时间 -1 表示没有限制
            max-wait: -1ms
            # 连接池中最大空闲连接
            max-idle: 10
            # 连接池中最小空闲连接
            min-idle: 5
        # 连接超时时间(毫秒)
        timeout: 2000
        # 指定客户端
        client-type: lettuce
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    三、配置redis序列化与发序列化方式

    package cn.mesmile.admin.common.config.redis;
    
    import com.fasterxml.jackson.annotation.JsonAutoDetect;
    import com.fasterxml.jackson.annotation.PropertyAccessor;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.redis.connection.RedisConnectionFactory;
    import org.springframework.data.redis.core.RedisTemplate;
    import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
    import org.springframework.data.redis.serializer.StringRedisSerializer;
    
    /**
     * @author zb
     * @Description 配置redis序列化与反序列化
     */
    @Configuration
    public class RedisConfig {
    
        /**
         *  配置redis序列化与反序列化
         * @param redisConnectionFactory
         * @return
         */
        @Bean
        public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
            RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
            redisTemplate.setConnectionFactory(redisConnectionFactory);
    
            // 使用Jackson2JsonRedisSerialize 替换默认序列化
            Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
            jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
    
            // 设置key和value的序列化规则
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
    
            // 设置hashKey和hashValue的序列化规则
            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
    
            // 设置支持事物
            //redisTemplate.setEnableTransactionSupport(true);
    
            redisTemplate.afterPropertiesSet();
    
            return redisTemplate;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-54cTpoII-1660446146574)(image/image_hDnzMjHztZ.png)]

    四、编写redis通用工具类

    package cn.mesmile.admin.common.utils;
    
    import org.springframework.data.redis.core.*;
    import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
    import org.springframework.lang.Nullable;
    import org.springframework.stereotype.Component;
    import org.springframework.util.Assert;
    
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.TimeUnit;
    import java.util.function.Supplier;
    
    /**
     * @author zb
     * @Description redis 工具类
     */
    @Component
    public class AdminRedisTemplate {
    
        private final RedisTemplate<String, Object> redisTemplate;
        private final ValueOperations<String, Object> valueOps;
        private final HashOperations<String, Object, Object> hashOps;
        private final ListOperations<String, Object> listOps;
        private final SetOperations<String, Object> setOps;
        private final ZSetOperations<String, Object> zSetOps;
    
        public AdminRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
            this.redisTemplate = redisTemplate;
            Assert.notNull(redisTemplate, "redisTemplate is null");
            this.valueOps = redisTemplate.opsForValue();
            this.hashOps = redisTemplate.opsForHash();
            this.listOps = redisTemplate.opsForList();
            this.setOps = redisTemplate.opsForSet();
            this.zSetOps = redisTemplate.opsForZSet();
        }
    
        /* ============================== 全局操作 ============================== */
    
        /**
         * 删除单个键值对
         *
         * @param key key
         * @return
         */
        public Boolean del(String key) {
            return this.redisTemplate.delete(key);
        }
    
        /**
         * 删除多个键值对
         *
         * @param keys 多个键值
         * @return 删除个数
         */
        public Long del(String... keys) {
            return this.del(Arrays.asList(keys));
        }
    
        /**
         * 删除多个键值对
         *
         * @param keys 多个键值
         * @return 删除个数
         */
        public Long del(Collection<String> keys) {
            return this.redisTemplate.delete(keys);
        }
    
        /**
         * 匹配 键值
         *
         * @param pattern 多个键值
         * @return 匹配到的键值
         */
        public Set<String> keys(String pattern) {
            return this.redisTemplate.keys(pattern);
        }
    
        /**
         * 判断是否存在某个key
         *
         * @param key key
         * @return 返回是否存在key
         */
        public Boolean exists(String key) {
            return this.redisTemplate.hasKey(key);
        }
    
        /**
         * 随机的返回一个key
         *
         * @return
         */
        public String randomKey() {
            return (String) this.redisTemplate.randomKey();
        }
    
        /**
         * 重命名 一个key名称
         *
         * @param oldKey 旧的key名称
         * @param newKey 新的key名称
         */
        public void rename(String oldKey, String newKey) {
            this.redisTemplate.rename(oldKey, newKey);
        }
    
        /**
         * 删除指定数据库中的指定key
         *
         * @param key     key
         * @param dbIndex 数据库下标
         * @return 返回是否删除成功
         */
        public Boolean move(String key, int dbIndex) {
            return this.redisTemplate.move(key, dbIndex);
        }
    
        /**
         * 设置某个key的过期时间
         *
         * @param key     key
         * @param seconds 过期时间单位 秒
         * @return 返回是否操作成功
         */
        public Boolean expire(String key, long seconds) {
            return this.redisTemplate.expire(key, seconds, TimeUnit.SECONDS);
        }
    
        /**
         * 设置某个key的过期时间
         *
         * @param key     key
         * @param timeout 过期时间
         * @return 返回是否操作成功
         */
        public Boolean expire(String key, Duration timeout) {
            return this.expire(key, timeout.getSeconds());
        }
    
        /**
         * 设置某个key在什么时候过期
         *
         * @param key  key
         * @param date 过期时间
         * @return 返回是否操作成功
         */
        public Boolean expireAt(String key, Date date) {
            return this.redisTemplate.expireAt(key, date);
        }
    
        /**
         * 设置某个key在什么时候过期
         *
         * @param key      key
         * @param unixTime 1970年1月1日到现在的秒数,过期时间
         * @return 返回是否操作成功
         */
        public Boolean expireAt(String key, long unixTime) {
            return this.expireAt(key, new Date(unixTime));
        }
    
        /**
         * 设置某个key的过期时间
         *
         * @param key          key
         * @param milliseconds 过期时间,单位毫秒
         * @return 返回是否操作成功
         */
        public Boolean pExpire(String key, long milliseconds) {
            return this.redisTemplate.expire(key, milliseconds, TimeUnit.MILLISECONDS);
        }
    
        /**
         * 用于删除键所指定的过期时间,将原来有过期时间的键 变为没有过期时间
         *
         * @param key key
         * @return 操作结果
         */
        public Boolean persist(String key) {
            return this.redisTemplate.persist(key);
        }
    
        /**
         * 获取键对应的值,存储的类型,存储在键中的值的数据类型
         *
         * @param key key
         * @return value存储类型
         */
        public String type(String key) {
            return this.redisTemplate.type(key).code();
        }
    
        /**
         * 获取key的过期时间,单位 秒
         *
         * @param key key
         * @return 过期时间
         */
        public Long ttl(String key) {
            return this.redisTemplate.getExpire(key);
        }
    
        /**
         * 键值
         *
         * @param key key
         * @return 过期时间
         */
        public Long millisecondsTtl(String key) {
            return this.redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
        }
    
    
        /* ============================== string字符串相关操作 =============================== */
    
        /**
         * 设置值
         *
         * @param key   key
         * @param value value
         */
        public void set(String key, Object value) {
            this.valueOps.set(key, value);
        }
    
        /**
         * 设置值的同时设置过期时间
         *
         * @param key     key
         * @param value   value
         * @param timeout 过期时间
         */
        public void setEx(String key, Object value, Duration timeout) {
            this.valueOps.set(key, value, timeout);
        }
    
        /**
         * 设置值的同时设置过期时间
         *
         * @param key     key
         * @param value   value
         * @param seconds 过期时间单位 秒
         */
        public void setEx(String key, Object value, Long seconds) {
            this.valueOps.set(key, value, seconds, TimeUnit.SECONDS);
        }
    
        /**
         * 获取值
         *
         * @param key key
         * @return T 返回值
         */
        @Nullable
        public <T> T get(String key) {
            return (T) this.valueOps.get(key);
        }
    
        /**
         * 获取值
         *
         * @param key    key
         * @param loader 若获取不到值则执行此语句
         */
        @Nullable
        public <T> T get(String key, Supplier<T> loader) {
            T value = this.get(key);
            if (value != null) {
                return value;
            } else {
                value = loader.get();
                if (value == null) {
                    return null;
                } else {
                    this.set(key, value);
                    return value;
                }
            }
        }
    
        /**
         * 一次性设置多个键值对
         *
         * @param keyValueMap 多个键值对
         */
        public void mSet(Map<String, Object> keyValueMap) {
            this.valueOps.multiSet(keyValueMap);
        }
    
        /**
         * 一次性获取多个key对应的value
         *
         * @param keys 多个key
         * @return 返回结果
         */
        public List<Object> mGet(String... keys) {
            return this.mGet(Arrays.asList(keys));
        }
    
        /**
         * 一次性获取多个key对应的value
         *
         * @param keys 多个key
         * @return 返回结果
         */
        public List<Object> mGet(Collection<String> keys) {
            return this.valueOps.multiGet(keys);
        }
    
        /**
         * 对指定key对应的value值递减,默认每次递减 1
         *
         * @param key key
         * @return 对指定key对应的value值递减后的值
         */
        public Long decr(String key) {
            return this.valueOps.decrement(key);
        }
    
        /**
         * 对指定key对应的value值递减,指定递减区间
         *
         * @param key       key
         * @param longValue 每次递减的区间
         * @return 对指定key对应的value值递减后的值
         */
        public Long decrBy(String key, long longValue) {
            return this.valueOps.decrement(key, longValue);
        }
    
        /**
         * 对指定key对应的value值递增,默认每次递增 1
         *
         * @param key key
         * @return 对指定key对应的value值递增后的值
         */
        public Long incr(String key) {
            return this.valueOps.increment(key);
        }
    
        /**
         * 对指定key对应的value值递增,指定递增区间
         *
         * @param key       key
         * @param longValue 每次递增的区间
         * @return 对指定key对应的value值递增后的值
         */
        public Long incrBy(String key, long longValue) {
            return this.valueOps.increment(key, longValue);
        }
    
        /**
         * 获取原来的值的同时将新的值设置进去
         *
         * @param key   key
         * @param value value
         * @return 返回值
         */
        public <T> T getSet(String key, Object value) {
            return (T) this.valueOps.getAndSet(key, value);
        }
    
        /* ============================== hash相关操作 =============================== */
    
        /**
         * 设置hash值
         *
         * @param key   key
         * @param field 属性
         * @param value value
         */
        public void hSet(String key, Object field, Object value) {
            this.hashOps.put(key, field, value);
        }
    
        /**
         * 一次性设置多个 hash值
         *
         * @param key  key
         * @param hash 多个键值对
         */
        public void hMset(String key, Map<Object, Object> hash) {
            this.hashOps.putAll(key, hash);
        }
    
        /**
         * 获取指定key对应,指定属性对应的值
         *
         * @param key   key
         * @param field 属性
         * @return value
         */
        public <T> T hGet(String key, Object field) {
            return (T) this.hashOps.get(key, field);
        }
    
        /**
         * 获取指定key对应,指定多个属性对应的多个值
         *
         * @param key    key
         * @param fields 多个属性
         * @return value
         */
        public List hmGet(String key, Object... fields) {
            return this.hmGet(key, Arrays.asList(fields));
        }
    
        /**
         * 获取指定key对应,指定多个属性对应的多个值
         *
         * @param key      key
         * @param hashKeys 多个属性
         * @return value
         */
        public List hmGet(String key, Collection<Object> hashKeys) {
            return this.hashOps.multiGet(key, hashKeys);
        }
    
        /**
         * 删除指定key对应指定多个属性键值对
         *
         * @param key    key
         * @param fields 多个属性
         * @return value
         */
        public Long hDel(String key, Object... fields) {
            return this.hashOps.delete(key, fields);
        }
    
        /**
         * 判断某个key,是否存在某个属性
         *
         * @param key   key
         * @param field 属性
         * @return 是否存在
         */
        public Boolean hExists(String key, Object field) {
            return this.hashOps.hasKey(key, field);
        }
    
        /**
         * 获取某个key对应的 所有键值对
         *
         * @param key key
         * @return 自定义key对应的所有键值对
         */
        public Map hGetAll(String key) {
            return this.hashOps.entries(key);
        }
    
        /**
         * 获取指定key,对应的所有 value值
         *
         * @param key key
         * @return 多个value值
         */
        public List hVals(String key) {
            return this.hashOps.values(key);
        }
    
        /**
         * 获取指定key,对应的所有 字段属性
         *
         * @param key key
         * @return 多个value字段属性
         */
        public Set<Object> hKeys(String key) {
            return this.hashOps.keys(key);
        }
    
        /**
         * 获取指定key,对应的 键值对 个数
         *
         * @param key key
         * @return key对应的 键值对 个数
         */
        public Long hLen(String key) {
            return this.hashOps.size(key);
        }
    
        /**
         * 将哈希字段的整数值按给定数字增加
         *
         * @param key   key
         * @param field 属性
         * @param value value
         * @return 增加后的value
         */
        public Long hIncrBy(String key, Object field, long value) {
            return this.hashOps.increment(key, field, value);
        }
    
        /**
         * 将哈希字段的浮点值按给定数值增加
         *
         * @param key   key
         * @param field 属性
         * @param value value
         * @return 增加后的value
         */
        public Double hIncrByFloat(String key, Object field, double value) {
            return this.hashOps.increment(key, field, value);
        }
    
        /* ============================== list相关操作 =============================== */
    
        /**
         * 通过其索引从列表获取元素
         *
         * @param key   key
         * @param index index
         * @return 通过其索引从列表获取元素
         */
        public <T> T lIndex(String key, long index) {
            return (T) this.listOps.index(key, index);
        }
    
        /**
         * 获取列表的长度
         *
         * @param key key
         * @return 列表的长度
         */
        public Long lLen(String key) {
            return this.listOps.size(key);
        }
    
        /**
         * 删除并获取列表中的第一个元素
         *
         * @param key key
         * @return value
         */
        public <T> T lPop(String key) {
            return (T) this.listOps.leftPop(key);
        }
    
        /**
         * 将一个或多个值添加到列表
         *
         * @param key    key
         * @param values values
         * @return 此次添加成功个数
         */
        public Long lPush(String key, Object... values) {
            return this.listOps.leftPush(key, values);
        }
    
        /**
         * 通过索引在列表中设置元素的值
         *
         * @param key   key
         * @param index 下标
         * @param value value
         */
        public void lSet(String key, long index, Object value) {
            this.listOps.set(key, index, value);
        }
    
        /**
         * 删除集合中值等于value的元素
         *
         * @param key   key
         * @param count count=0, 删除所有值等于value的元素;
         *              count>0, 从头部开始删除第一个值等于value的元素;
         *              count<0, 从尾部开始删除第一个值等于value的元素;
         * @param value value
         * @return 删除个数
         */
        public Long lRem(String key, long count, Object value) {
            return this.listOps.remove(key, count, value);
        }
    
        /**
         * 从列表中获取一系列元素
         *
         * @param key   key
         * @param start 开始下标, 0是开始位置
         * @param end   结束下标   -1返回所有
         * @return
         */
        public List lRange(String key, long start, long end) {
            return this.listOps.range(key, start, end);
        }
    
        /**
         * 裁剪list
         *
         * @param key   key
         * @param start 开始下标, 0是开始位置
         * @param end   结束下标   -1所有
         */
        public void lTrim(String key, long start, long end) {
            this.listOps.trim(key, start, end);
        }
    
        /**
         * 移除并获取列表最后一个元素
         *
         * @param key key
         * @return 列表最后一个元素
         */
        public <T> T rPop(String key) {
            return (T) this.listOps.rightPop(key);
        }
    
        /**
         * 将一个或多个值附加到列表
         *
         * @param key    key
         * @param values values
         * @return 添加成功的个数
         */
        public Long rPush(String key, Object... values) {
            return this.listOps.rightPush(key, values);
        }
    
        /**
         * 删除列表中的最后一个元素,将其附加到另一个列表并返回
         *
         * @param srcKey
         * @param dstKey
         * @return
         */
        public <T> T rPopLPush(String srcKey, String dstKey) {
            return (T) this.listOps.rightPopAndLeftPush(srcKey, dstKey);
        }
    
        /* ============================== set相关操作 =============================== */
    
        /**
         * 将一个或多个成员添加到集合
         *
         * @param key     key
         * @param members 一个或多个value值
         * @return
         */
        public Long sAdd(String key, Object... members) {
            return this.setOps.add(key, members);
        }
    
        /**
         * 从集合中删除并返回随机成员
         *
         * @param key key
         * @return 从集合中删除并返回随机成员
         */
        public <T> T sPop(String key) {
            return (T) this.setOps.pop(key);
        }
    
        /**
         * 返回集合中的所有成员
         *
         * @param key key
         * @return 返回集合中的所有成员
         */
        public Set sMembers(String key) {
            return this.setOps.members(key);
        }
    
        /**
         * 判断 member 元素是否是集合 key 的成员
         *
         * @param key    key
         * @param member member
         * @return 判断 member 元素是否是集合 key 的成员
         */
        public boolean sIsMember(String key, Object member) {
            return this.setOps.isMember(key, member);
        }
    
        /**
         * 返回给定所有给定集合的交集
         *
         * @param key      key
         * @param otherKey otherKey
         * @return 交集
         */
        public Set sInter(String key, String otherKey) {
            return this.setOps.intersect(key, otherKey);
        }
    
        /**
         * 返回集合中给定所有集合的交集 并存储在 key 对应的集合中
         *
         * @param key       key
         * @param otherKeys otherKeys
         * @return 返回集合中给定所有集合的交集 并存储在 key 对应的集合中
         */
        public Set sInter(String key, Collection<String> otherKeys) {
            return this.setOps.intersect(key, otherKeys);
        }
    
        /**
         * 返回集合中一个随机数
         *
         * @param key key
         * @return 返回集合中一个随机数
         */
        public <T> T sRandMember(String key) {
            return (T) this.setOps.randomMember(key);
        }
    
        /**
         * 返回集合中多个随机数
         *
         * @param key   key
         * @param count 返回个数
         * @return 返回集合中多个随机数
         */
        public List sRandMember(String key, int count) {
            return this.setOps.randomMembers(key, (long) count);
        }
    
        /**
         * 移除集合中一个或多个成员
         *
         * @param key     key
         * @param members members
         * @return 移除成功个数
         */
        public Long sRem(String key, Object... members) {
            return this.setOps.remove(key, members);
        }
    
        /**
         * 返回所有给定集合的并集
         *
         * @param key      key
         * @param otherKey otherKey
         * @return 返回所有给定集合的并集
         */
        public Set sUnion(String key, String otherKey) {
            return this.setOps.union(key, otherKey);
        }
    
        /**
         * 返回集合中给定所有集合的并集 并存储在 key 对应的集合中
         *
         * @param key       key
         * @param otherKeys otherKeys
         * @return 返回集合中给定所有集合的并集 并存储在 key 对应的集合中
         */
        public Set sUnion(String key, Collection<String> otherKeys) {
            return this.setOps.union(key, otherKeys);
        }
    
        /**
         * 返回第一个集合与其他集合之间的差异
         *
         * @param key      key
         * @param otherKey otherKey
         * @return 返回第一个集合与其他集合之间的差异
         */
        public Set sDiff(String key, String otherKey) {
            return this.setOps.difference(key, otherKey);
        }
    
        /**
         * 返回给定所有集合的差集并存储在 key 中
         *
         * @param key       key
         * @param otherKeys otherKeys
         * @return 返回给定所有集合的差集并存储在 key 中
         */
        public Set sDiff(String key, Collection<String> otherKeys) {
            return this.setOps.difference(key, otherKeys);
        }
    
    
        /* ============================== zSet相关操作 =============================== */
    
        /**
         * 获取有序集合的成员数
         *
         * @param key    key
         * @param member member
         * @param score  分数
         * @return 是否添加成功
         */
        public Boolean zAdd(String key, Object member, double score) {
            return this.zSetOps.add(key, member, score);
        }
    
        /**
         * 向有序集合添加一个或多个成员,或者更新已存在成员的分数
         *
         * @param key          key
         * @param scoreMembers scoreMembers
         * @return 添加成功的个数
         */
        public Long zAdd(String key, Map<Object, Double> scoreMembers) {
            Set<TypedTuple<Object>> tuples = new HashSet();
            scoreMembers.forEach((k, v) -> {
                tuples.add(new DefaultTypedTuple(k, v));
            });
            return this.zSetOps.add(key, tuples);
        }
    
        /**
         * 获取有序集合的成员数
         *
         * @param key key
         * @return 获取有序集合的成员数
         */
        public Long zCard(String key) {
            return this.zSetOps.zCard(key);
        }
    
        /**
         * 计算在有序集合中指定区间分数的成员数
         *
         * @param key key
         * @param min 最小值
         * @param max 最大值
         * @return 计算在有序集合中指定区间分数的成员数
         */
        public Long zCount(String key, double min, double max) {
            return this.zSetOps.count(key, min, max);
        }
    
        /**
         * 有序集合中对指定成员的分数加上增量 score
         *
         * @param key    key
         * @param member 成员
         * @param score  分数
         * @return 增加后的分数
         */
        public Double zIncrBy(String key, Object member, double score) {
            return this.zSetOps.incrementScore(key, member, score);
        }
    
        /**
         * 通过索引区间返回有序集合指定区间内的成员
         * start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。
         * 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。
         *
         * @param key   key
         * @param start 开始
         * @param end   结束
         * @return 区间成员
         */
        public Set zRange(String key, long start, long end) {
            return this.zSetOps.range(key, start, end);
        }
    
        /**
         * 返回有序集中指定区间内的成员,通过索引,分数从高到低
         *
         * @param key   key
         * @param start 开始
         * @param end   结束
         * @return 区间成员
         */
        public Set zRevrange(String key, long start, long end) {
            return this.zSetOps.reverseRange(key, start, end);
        }
    
        /**
         * 通过分数返回有序集合指定区间内的成员
         *
         * @param key key
         * @param min 最小分数
         * @param max 最大分数
         * @return 区间成员
         */
        public Set zRangeByScore(String key, double min, double max) {
            return this.zSetOps.rangeByScore(key, min, max);
        }
    
        /**
         * 返回有序集合中指定成员的索引,默认按分数递增(从小到大)
         *
         * @param key    key
         * @param member 成员
         * @return 排序索引
         */
        public Long zRank(String key, Object member) {
            return this.zSetOps.rank(key, member);
        }
    
        /**
         * 返回有序集合中指定成员的排名,有序集成员按分数值递减(从大到小)排序
         *
         * @param key    key
         * @param member 成员
         * @return 排序索引
         */
        public Long zRevrank(String key, Object member) {
            return this.zSetOps.reverseRank(key, member);
        }
    
        /**
         * 移除有序集合中的一个或多个成员
         *
         * @param key     key
         * @param members 一个或多个成员
         * @return 移除成功个数
         */
        public Long zRem(String key, Object... members) {
            return this.zSetOps.remove(key, members);
        }
    
        /**
         * 返回有序集中,成员的分数值
         *
         * @param key    key
         * @param member 成员
         * @return 成员的分数值
         */
        public Double zScore(String key, Object member) {
            return this.zSetOps.score(key, member);
        }
    
        public RedisTemplate<String, Object> getRedisTemplate() {
            return this.redisTemplate;
        }
    
        public ValueOperations<String, Object> getValueOps() {
            return this.valueOps;
        }
    
        public HashOperations<String, Object, Object> getHashOps() {
            return this.hashOps;
        }
    
        public ListOperations<String, Object> getListOps() {
            return this.listOps;
        }
    
        public SetOperations<String, Object> getSetOps() {
            return this.setOps;
        }
    
        public ZSetOperations<String, Object> getZSetOps() {
            return this.zSetOps;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824
    • 825
    • 826
    • 827
    • 828
    • 829
    • 830
    • 831
    • 832
    • 833
    • 834
    • 835
    • 836
    • 837
    • 838
    • 839
    • 840
    • 841
    • 842
    • 843
    • 844
    • 845
    • 846
    • 847
    • 848
    • 849
    • 850
    • 851
    • 852
    • 853
    • 854
    • 855
    • 856
    • 857
    • 858
    • 859
    • 860
    • 861
    • 862
    • 863
    • 864
    • 865
    • 866
    • 867
    • 868
    • 869
    • 870
    • 871
    • 872
    • 873
    • 874
    • 875
    • 876
    • 877
    • 878
    • 879
    • 880
    • 881
    • 882
    • 883
    • 884
    • 885
    • 886
    • 887
    • 888
    • 889
    • 890
    • 891
    • 892
    • 893
    • 894
    • 895
    • 896
    • 897
    • 898
    • 899
    • 900
    • 901
    • 902
    • 903
    • 904
    • 905
    • 906
    • 907
    • 908
    • 909
    • 910
    • 911
    • 912
    • 913
    • 914
    • 915
    • 916
    • 917
    • 918
    • 919
    • 920
    • 921
    • 922
    • 923
    • 924
    • 925
    • 926
    • 927
    • 928
    • 929
    • 930
    • 931
    • 932
    • 933
    • 934
    • 935
    • 936
    • 937
    • 938
    • 939
    • 940
    • 941
    • 942
  • 相关阅读:
    安卓Termux搭建web服务器【公网远程手机Android服务器】
    深度分析:用户最喜欢用哪种NFT做头像
    LeetCode——1175.质数排列
    01【SpringMVC快速入门】
    php二维数组查找某个id=1的元素
    Spring 框架中都用到了哪些设计模式:单例模式、策略模式、代理模式
    一分钟带你了解智能遥测终端机RTU
    Docker以只读挂载磁盘命令
    多态的定义 以及 虚函数重写(覆盖)
    ZZ308 物联网应用与服务赛题第F套
  • 原文地址:https://blog.csdn.net/suprezheng/article/details/126329484