From b199b651ecf8a2de6cccafa4efc98c7d65446ebd Mon Sep 17 00:00:00 2001 From: Charles7c Date: Mon, 17 Mar 2025 21:24:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(cache/redisson):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E6=80=A7=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20setIfAbsent=E3=80=81setIfExists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/redisson/util/RedisUtils.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) 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); + } + /** * 查询指定缓存 *