diff --git a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java index a9458bf3..5e9cb6a2 100644 --- a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java +++ b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java @@ -62,6 +62,62 @@ public class RedisUtils { CLIENT.getBucket(key).set(value, duration); } + /** + * 设置缓存 + * + *

如果键已存在,则不设置

+ * + * @param key 键 + * @param value 值 + * @return true:设置成功;false:设置失败 + * @since 2.10.0 + */ + public static boolean setIfAbsent(String key, T value) { + return CLIENT.getBucket(key).setIfAbsent(value); + } + + /** + * 设置缓存 + * + *

如果键已存在,则不设置

+ * + * @param key 键 + * @param value 值 + * @param duration 过期时间 + * @return true:设置成功;false:设置失败 + * @since 2.10.0 + */ + public static boolean setIfAbsent(String key, T value, Duration duration) { + return CLIENT.getBucket(key).setIfAbsent(value, duration); + } + + /** + * 设置缓存 + *

如果键不存在,则不设置

+ * + * @param key 键 + * @param value 值 + * @return true:设置成功;false:设置失败 + * @since 2.10.0 + */ + public static boolean setIfExists(String key, T value) { + return CLIENT.getBucket(key).setIfExists(value); + } + + /** + * 设置缓存 + *

如果键不存在,则不设置

+ * + * @param key 键 + * @param value 值 + * @param duration 过期时间 + * @return true:设置成功;false:设置失败 + * @since 2.10.0 + */ + public static boolean setIfExists(String key, T value, Duration duration) { + return CLIENT.getBucket(key).setIfExists(value, duration); + } + /** * 查询指定缓存 *