mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-19 21:45:06 +08:00
增加 redis key 查询接口
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package cn.iocoder.dashboard.framework.redis.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@ -24,15 +26,20 @@ public class RedisKeyDefine {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 过期时间 - 永不过期
|
||||
*/
|
||||
public static final Duration TIMEOUT_FOREVER = null;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TimeoutTypeEnum {
|
||||
|
||||
/**
|
||||
* 过期时间 - 动态,通过参数传入
|
||||
*/
|
||||
public static final Duration TIMEOUT_DYNAMIC = null;
|
||||
FOREVER(1), // 永不超时
|
||||
DYNAMIC(2), // 动态超时
|
||||
FIXED(3); // 固定超时
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Key 模板
|
||||
@ -48,10 +55,12 @@ public class RedisKeyDefine {
|
||||
* 如果是使用分布式锁,设置为 {@link java.util.concurrent.locks.Lock} 类型
|
||||
*/
|
||||
private final Class<?> valueType;
|
||||
/**
|
||||
* 超时类型
|
||||
*/
|
||||
private final TimeoutTypeEnum timeoutType;
|
||||
/**
|
||||
* 过期时间
|
||||
*
|
||||
* 为空时,表示永不过期 {@link #TIMEOUT_FOREVER}
|
||||
*/
|
||||
private final Duration timeout;
|
||||
|
||||
@ -59,7 +68,20 @@ public class RedisKeyDefine {
|
||||
this.keyTemplate = keyTemplate;
|
||||
this.keyType = keyType;
|
||||
this.valueType = valueType;
|
||||
this.timeoutType = TimeoutTypeEnum.FIXED;
|
||||
this.timeout = timeout;
|
||||
// 添加注册表
|
||||
RedisKeyRegistry.add(this);
|
||||
}
|
||||
|
||||
public RedisKeyDefine(String keyTemplate, KeyTypeEnum keyType, Class<?> valueType, TimeoutTypeEnum timeoutType) {
|
||||
this.keyTemplate = keyTemplate;
|
||||
this.keyType = keyType;
|
||||
this.valueType = valueType;
|
||||
this.timeoutType = timeoutType;
|
||||
this.timeout = Duration.ZERO;
|
||||
// 添加注册表
|
||||
RedisKeyRegistry.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.dashboard.framework.redis.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link RedisKeyDefine} 注册表
|
||||
*/
|
||||
public class RedisKeyRegistry {
|
||||
|
||||
private static final List<RedisKeyDefine> defines = new ArrayList<>();
|
||||
|
||||
public static void add(RedisKeyDefine define) {
|
||||
defines.add(define);
|
||||
}
|
||||
|
||||
public static List<RedisKeyDefine> list() {
|
||||
return defines;
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return defines.size();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user