From cd6bfb2a3a6b942f43253b24cef8461593dec60f Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 26 六月 2023 23:37:21 +0800 Subject: [PATCH] add 新增 RedisUtils.setObjectIfAbsent 如果不存在则设置 方法 --- ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java index fd20ba0..9f59f69 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java @@ -1,8 +1,8 @@ package org.dromara.common.redis.utils; -import org.dromara.common.core.utils.SpringUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.dromara.common.core.utils.SpringUtils; import org.redisson.api.*; import java.time.Duration; @@ -127,6 +127,18 @@ bucket.setAsync(value); bucket.expireAsync(duration); batch.execute(); + } + + /** + * 濡傛灉涓嶅瓨鍦ㄥ垯璁剧疆 骞惰繑鍥� true 濡傛灉瀛樺湪鍒欒繑鍥� false + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param value 缂撳瓨鐨勫�� + * @return set鎴愬姛鎴栧け璐� + */ + public static <T> boolean setObjectIfAbsent(final String key, final T value, final Duration duration) { + RBucket<T> bucket = CLIENT.getBucket(key); + return bucket.setIfAbsent(value, duration); } /** @@ -375,6 +387,21 @@ } /** + * 鍒犻櫎Hash涓殑鏁版嵁 + * + * @param key Redis閿� + * @param hKeys Hash閿� + */ + public static <T> void delMultiCacheMapValue(final String key, final Set<String> hKeys) { + RBatch batch = CLIENT.createBatch(); + RMapAsync<String, T> rMap = batch.getMap(key); + for (String hKey : hKeys) { + rMap.removeAsync(hKey); + } + batch.execute(); + } + + /** * 鑾峰彇澶氫釜Hash涓殑鏁版嵁 * * @param key Redis閿� -- Gitblit v1.9.3