From cb9ed5add0c840168f4f6635736ecd2b42f425be Mon Sep 17 00:00:00 2001 From: AprilWind <2100166581@qq.com> Date: 星期二, 14 五月 2024 17:05:52 +0800 Subject: [PATCH] update 新增工具类注释 --- ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java | 84 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 83 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..faed92d 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; @@ -65,6 +65,12 @@ consumer.accept(msg); } + /** + * 鍙戝竷娑堟伅鍒版寚瀹氱殑棰戦亾 + * + * @param channelKey 閫氶亾key + * @param msg 鍙戦�佹暟鎹� + */ public static <T> void publish(String channelKey, T msg) { RTopic topic = CLIENT.getTopic(channelKey); topic.publish(msg); @@ -127,6 +133,30 @@ 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); + } + + /** + * 濡傛灉瀛樺湪鍒欒缃� 骞惰繑鍥� true 濡傛灉瀛樺湪鍒欒繑鍥� false + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param value 缂撳瓨鐨勫�� + * @return set鎴愬姛鎴栧け璐� + */ + public static <T> boolean setObjectIfExists(final String key, final T value, final Duration duration) { + RBucket<T> bucket = CLIENT.getBucket(key); + return bucket.setIfExists(value, duration); } /** @@ -231,6 +261,18 @@ } /** + * 杩藉姞缂撳瓨List鏁版嵁 + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param data 寰呯紦瀛樼殑鏁版嵁 + * @return 缂撳瓨鐨勫璞� + */ + public static <T> boolean addCacheList(final String key, final T data) { + RList<T> rList = CLIENT.getList(key); + return rList.add(data); + } + + /** * 娉ㄥ唽List鐩戝惉鍣� * <p> * key 鐩戝惉鍣ㄩ渶寮�鍚� `notify-keyspace-events` 绛� redis 鐩稿叧閰嶇疆 @@ -255,6 +297,19 @@ } /** + * 鑾峰緱缂撳瓨鐨刲ist瀵硅薄(鑼冨洿) + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param form 璧峰涓嬫爣 + * @param to 鎴涓嬫爣 + * @return 缂撳瓨閿�煎搴旂殑鏁版嵁 + */ + public static <T> List<T> getCacheListRange(final String key, int form, int to) { + RList<T> rList = CLIENT.getList(key); + return rList.range(form, to); + } + + /** * 缂撳瓨Set * * @param key 缂撳瓨閿�� @@ -264,6 +319,18 @@ public static <T> boolean setCacheSet(final String key, final Set<T> dataSet) { RSet<T> rSet = CLIENT.getSet(key); return rSet.addAll(dataSet); + } + + /** + * 杩藉姞缂撳瓨Set鏁版嵁 + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param data 寰呯紦瀛樼殑鏁版嵁 + * @return 缂撳瓨鐨勫璞� + */ + public static <T> boolean addCacheSet(final String key, final T data) { + RSet<T> rSet = CLIENT.getSet(key); + return rSet.add(data); } /** @@ -375,6 +442,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