Quellcode durchsuchen

update 优化 setCacheObject 简化写法

疯狂的狮子Li vor 11 Monaten
Ursprung
Commit
a545f7fc44

+ 4 - 7
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java

@@ -129,9 +129,9 @@ public class RedisUtils {
             } catch (Exception e) {
                 long timeToLive = bucket.remainTimeToLive();
                 if (timeToLive == -1) {
-                    setCacheObject(key, value);
+                    bucket.set(value);
                 } else {
-                    setCacheObject(key, value, Duration.ofMillis(timeToLive));
+                    bucket.set(value, Duration.ofMillis(timeToLive));
                 }
             }
         } else {
@@ -147,11 +147,8 @@ public class RedisUtils {
      * @param duration 时间
      */
     public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
-        RBatch batch = CLIENT.createBatch();
-        RBucketAsync<T> bucket = batch.getBucket(key);
-        bucket.setAsync(value);
-        bucket.expireAsync(duration);
-        batch.execute();
+        RBucket<T> bucket = CLIENT.getBucket(key);
+        bucket.set(value, duration);
     }
 
     /**