|
|
|
@ -6,11 +6,11 @@ import lombok.AccessLevel;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
import org.redisson.api.*;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -107,7 +107,7 @@ public class RedisUtils {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
long timeToLive = bucket.remainTimeToLive();
|
|
|
|
|
bucket.set(value);
|
|
|
|
|
bucket.expire(timeToLive, TimeUnit.MILLISECONDS);
|
|
|
|
|
bucket.expire(Duration.ofMillis(timeToLive));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
bucket.set(value);
|
|
|
|
@ -119,13 +119,12 @@ public class RedisUtils {
|
|
|
|
|
*
|
|
|
|
|
* @param key 缓存的键值
|
|
|
|
|
* @param value 缓存的值
|
|
|
|
|
* @param timeout 时间
|
|
|
|
|
* @param timeUnit 时间颗粒度
|
|
|
|
|
* @param duration 时间
|
|
|
|
|
*/
|
|
|
|
|
public static <T> void setCacheObject(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
|
|
|
|
|
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(timeout, timeUnit);
|
|
|
|
|
result.expire(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -149,20 +148,19 @@ public class RedisUtils {
|
|
|
|
|
* @return true=设置成功;false=设置失败
|
|
|
|
|
*/
|
|
|
|
|
public static boolean expire(final String key, final long timeout) {
|
|
|
|
|
return expire(key, timeout, TimeUnit.SECONDS);
|
|
|
|
|
return expire(key, Duration.ofSeconds(timeout));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置有效时间
|
|
|
|
|
*
|
|
|
|
|
* @param key Redis键
|
|
|
|
|
* @param timeout 超时时间
|
|
|
|
|
* @param unit 时间单位
|
|
|
|
|
* @param key Redis键
|
|
|
|
|
* @param duration 超时时间
|
|
|
|
|
* @return true=设置成功;false=设置失败
|
|
|
|
|
*/
|
|
|
|
|
public static boolean expire(final String key, final long timeout, final TimeUnit unit) {
|
|
|
|
|
public static boolean expire(final String key, final Duration duration) {
|
|
|
|
|
RBucket rBucket = CLIENT.getBucket(key);
|
|
|
|
|
return rBucket.expire(timeout, unit);
|
|
|
|
|
return rBucket.expire(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|