陈昶聿
12 小时以前 1d76f1864c507b99b153d63d53d7bb7f32c89ec3
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -30,6 +30,10 @@
        redisTemplate.opsForValue().set(key, value);
    }
    public <T> void setCacheList(final String key, final List<T> values) {
        redisTemplate.opsForList().rightPushAll(key, values);
    }
    /**
     * 缓存基本的对象,Integer、String、实体类等
     *
@@ -299,4 +303,27 @@
    public Collection<String> keys(final String pattern) {
        return redisTemplate.keys(pattern);
    }
    /**
     * 获取当前key值的数量
     * @param key
     * @return
     */
    public Long getListSize(String key) {
        // 检查 key 类型
        DataType keyType = redisTemplate.type(key);
        // 如果 key 不存在,返回 0
        if (keyType == DataType.NONE) {
            return 0L;
        }
        // 如果不是 List 类型,删除它并返回 0(防止 WRONGTYPE 错误)
        if (keyType != DataType.LIST) {
            redisTemplate.delete(key);
            return 0L;
        }
        return redisTemplate.opsForList().size(key);
    }
}