增加 redis key 查询接口

This commit is contained in:
YunaiV
2021-01-27 01:06:58 +08:00
parent d9114504f8
commit 842496a534
6 changed files with 121 additions and 17 deletions

View File

@ -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);
}
}

View File

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