zouyu
2025-10-17 c65ab218b14e87489f1594b2d932f7bd54b3ba11
ruoyi-common/src/main/java/com/ruoyi/common/utils/RedisUtil.java
@@ -153,6 +153,7 @@
    public static boolean set(String key, Object value) {
        try {
            redisTemplate.opsForValue().set(key, value);
            return true;
        } catch (Exception e) {
@@ -470,7 +471,7 @@
     * @param start 开始
     * @param end   结束 0 到 -1代表所有值
     */
    public static List<Object> lGet(String key, long start, long end) {
    public static List<?> lGet(String key, long start, long end) {
        try {
            return redisTemplate.opsForList().range(key, start, end);
        } catch (Exception e) {
@@ -556,7 +557,7 @@
     * @param value 值
     * @return true 存放成功 false存放失败
     */
    public static boolean lSet(String key, List<Object> value) {
    public static boolean lSet(String key, List<?> value) {
        try {
            redisTemplate.opsForList().rightPushAll(key, value);
            return true;
@@ -576,7 +577,7 @@
     * @param time  时间(秒)
     * @return true 存放成功 false存放失败
     */
    public static boolean lSet(String key, List<Object> value, long time) {
    public static boolean lSet(String key, List<?> value, long time) {
        try {
            if (time > 0) {
                redisTemplate.opsForList().rightPushAll(key, value);
@@ -627,5 +628,54 @@
            return 0;
        }
    }
    //====================================================ZSet=======================================================
    /**
     * 获取zset数据长度
     * @param key 键
     * @return
     */
    public static long getZSetSize(String key){
        try {
            return redisTemplate.opsForZSet().size(key);
        }catch (Exception e){
            e.printStackTrace();
            return 0L;
        }
    }
    /**
     * 新增一个zset
     * @param key    键
     * @param source 分数
     * @param value  值
     * @return
     */
    public static boolean addZSet(String key,double source,Object value){
        try {
            return redisTemplate.opsForZSet().add(key, value, source);
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 删除zset元素,按排名
     * @param key   键
     * @param start 开始索引
     * @param end   结束索引
     * @return
     */
    public static long delZSetRange(String key,long start,long end){
        try {
            return redisTemplate.opsForZSet().removeRange(key,start,end);
        }catch(Exception e){
            e.printStackTrace();
            return 0L;
        }
    }
}