陈昶聿
3 天以前 d7e3192804fca756d881af360ffd5eea157ef9ad
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -50,6 +50,20 @@
    }
    /**
     * 缓存对象,仅当 key 不存在时才写入(原子操作),用于幂等互斥标记
     *
     * @param key      缓存的键值
     * @param value    缓存的值
     * @param timeout  时间
     * @param timeUnit 时间颗粒度
     * @return true=本次写入成功(之前不存在);false=key 已存在,未写入
     */
    public <T> boolean setCacheObjectIfAbsent(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
        Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
        return Boolean.TRUE.equals(success);
    }
    /**
     * 设置有效时间
     *
     * @param key     Redis键