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(); } /**