mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-23 23:09:47 +08:00
update 优化 setCacheObject 简化写法
This commit is contained in:
@ -129,9 +129,9 @@ public class RedisUtils {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
long timeToLive = bucket.remainTimeToLive();
|
long timeToLive = bucket.remainTimeToLive();
|
||||||
if (timeToLive == -1) {
|
if (timeToLive == -1) {
|
||||||
setCacheObject(key, value);
|
bucket.set(value);
|
||||||
} else {
|
} else {
|
||||||
setCacheObject(key, value, Duration.ofMillis(timeToLive));
|
bucket.set(value, Duration.ofMillis(timeToLive));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -147,11 +147,8 @@ public class RedisUtils {
|
|||||||
* @param duration 时间
|
* @param duration 时间
|
||||||
*/
|
*/
|
||||||
public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
|
public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
|
||||||
RBatch batch = CLIENT.createBatch();
|
RBucket<T> bucket = CLIENT.getBucket(key);
|
||||||
RBucketAsync<T> bucket = batch.getBucket(key);
|
bucket.set(value, duration);
|
||||||
bucket.setAsync(value);
|
|
||||||
bucket.expireAsync(duration);
|
|
||||||
batch.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user