From 70ca157c07b6507fc40eb6bc53c1d4c20e99219f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 22 Jul 2022 17:35:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20RedisUtils=20?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=20set=20ttl=20=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/redis/utils/RedisUtils.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java index 8a83aaf5..48a3548f 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java @@ -110,14 +110,13 @@ public class RedisUtils { * @since Redis 6.X 以上使用 setAndKeepTTL 兼容 5.X 方案 */ public static void setCacheObject(final String key, final T value, final boolean isSaveTtl) { - RBucket bucket = CLIENT.getBucket(key); + RBucket 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 +131,11 @@ public class RedisUtils { * @param duration 时间 */ public static void setCacheObject(final String key, final T value, final Duration duration) { - RBucket result = CLIENT.getBucket(key); - result.set(value); - result.expire(duration); + RBatch batch = CLIENT.createBatch(); + RBucketAsync bucket = batch.getBucket(key); + bucket.setAsync(value); + bucket.expireAsync(duration); + batch.execute(); } /**