From 9d6b0b35a33a6d6abe56bb1b92135df01c5b4567 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 19 十二月 2022 14:30:01 +0800
Subject: [PATCH] update redisson 3.18.0 => 3.19.0

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java |   41 ++++++++++++++++++++++-------------------
 1 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java
index 20f3ea3..ecba4ca 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java
@@ -4,7 +4,6 @@
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.redisson.api.*;
-import org.redisson.config.Config;
 
 import java.time.Duration;
 import java.util.Collection;
@@ -26,14 +25,6 @@
 public class RedisUtils {
 
     private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
-
-    public static NameMapper getNameMapper() {
-        Config config = CLIENT.getConfig();
-        if (config.isClusterConfig()) {
-            return config.useClusterServers().getNameMapper();
-        }
-        return config.useSingleServer().getNameMapper();
-    }
 
     /**
      * 闄愭祦
@@ -110,14 +101,13 @@
      * @since Redis 6.X 浠ヤ笂浣跨敤 setAndKeepTTL 鍏煎 5.X 鏂规
      */
     public static <T> void setCacheObject(final String key, final T value, final boolean isSaveTtl) {
-        RBucket<Object> bucket = CLIENT.getBucket(key);
+        RBucket<T> bucket = CLIENT.getBucket(key);
         if (isSaveTtl) {
             try {
                 bucket.setAndKeepTTL(value);
             } catch (Exception e) {
                 long timeToLive = bucket.remainTimeToLive();
-                bucket.set(value);
-                bucket.expire(Duration.ofMillis(timeToLive));
+                setCacheObject(key, value, Duration.ofMillis(timeToLive));
             }
         } else {
             bucket.set(value);
@@ -132,9 +122,11 @@
      * @param duration 鏃堕棿
      */
     public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
-        RBucket<T> result = CLIENT.getBucket(key);
-        result.set(value);
-        result.expire(duration);
+        RBatch batch = CLIENT.createBatch();
+        RBucketAsync<T> bucket = batch.getBucket(key);
+        bucket.setAsync(value);
+        bucket.expireAsync(duration);
+        batch.execute();
     }
 
     /**
@@ -327,6 +319,17 @@
     }
 
     /**
+     * 鑾峰緱缂撳瓨Map鐨刱ey鍒楄〃
+     *
+     * @param key 缂撳瓨鐨勯敭鍊�
+     * @return key鍒楄〃
+     */
+    public static <T> Set<String> getCacheMapKeySet(final String key) {
+        RMap<String, T> rMap = CLIENT.getMap(key);
+        return rMap.keySet();
+    }
+
+    /**
      * 寰�Hash涓瓨鍏ユ暟鎹�
      *
      * @param key   Redis閿�
@@ -425,8 +428,8 @@
      * @return 瀵硅薄鍒楄〃
      */
     public static Collection<String> keys(final String pattern) {
-        Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(getNameMapper().map(pattern));
-        return stream.map(key -> getNameMapper().unmap(key)).collect(Collectors.toList());
+        Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
+        return stream.collect(Collectors.toList());
     }
 
     /**
@@ -435,7 +438,7 @@
      * @param pattern 瀛楃涓插墠缂�
      */
     public static void deleteKeys(final String pattern) {
-        CLIENT.getKeys().deleteByPattern(getNameMapper().map(pattern));
+        CLIENT.getKeys().deleteByPattern(pattern);
     }
 
     /**
@@ -445,6 +448,6 @@
      */
     public static Boolean hasKey(String key) {
         RKeys rKeys = CLIENT.getKeys();
-        return rKeys.countExists(getNameMapper().map(key)) > 0;
+        return rKeys.countExists(key) > 0;
     }
 }

--
Gitblit v1.9.3