From ec004e9ba376c902c63d1450af3f85dd093205bf Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 16 一月 2023 14:11:45 +0800
Subject: [PATCH] add 增加 (开发、测试、打包)期间必备的jvm参数

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java |   49 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 40 insertions(+), 9 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 7ed3b28..1623808 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
@@ -1,6 +1,5 @@
 package com.ruoyi.common.utils.redis;
 
-import cn.hutool.core.collection.IterUtil;
 import com.ruoyi.common.utils.spring.SpringUtils;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
@@ -12,6 +11,8 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * redis 宸ュ叿绫�
@@ -100,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);
@@ -122,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();
     }
 
     /**
@@ -205,6 +207,15 @@
             batch.getBucket(t.toString()).deleteAsync();
         });
         batch.execute();
+    }
+
+    /**
+     * 妫�鏌ョ紦瀛樺璞℃槸鍚﹀瓨鍦�
+     *
+     * @param key 缂撳瓨鐨勯敭鍊�
+     */
+    public static boolean isExistsObject(final String key) {
+        return CLIENT.getBucket(key).isExists();
     }
 
     /**
@@ -317,6 +328,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閿�
@@ -415,8 +437,17 @@
      * @return 瀵硅薄鍒楄〃
      */
     public static Collection<String> keys(final String pattern) {
-        Iterable<String> iterable = CLIENT.getKeys().getKeysByPattern(pattern);
-        return IterUtil.toList(iterable);
+        Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
+        return stream.collect(Collectors.toList());
+    }
+
+    /**
+     * 鍒犻櫎缂撳瓨鐨勫熀鏈璞″垪琛�
+     *
+     * @param pattern 瀛楃涓插墠缂�
+     */
+    public static void deleteKeys(final String pattern) {
+        CLIENT.getKeys().deleteByPattern(pattern);
     }
 
     /**

--
Gitblit v1.9.3