初始化字典数据至内存

This commit is contained in:
xy
2024-10-16 18:52:27 +08:00
parent 59522c66d9
commit 29c1f2a530
5 changed files with 68 additions and 6 deletions

View File

@@ -95,4 +95,19 @@ public interface AppRedisKey {
String DOWNLOAD = "downloadKey:";
String CONTROL = "control:";
/**
* 设备池
*/
String DEVICE_LIST = "deviceListKey";
/**
* 字典树
*/
String DICT_TREE = "dictTreeKey";
/**
* 模板
*/
String DEV_MODEL = "devModelKey:";
}

View File

@@ -3,6 +3,7 @@ package com.njcn.redis.utils;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.*;
@@ -79,6 +80,17 @@ public class RedisUtil {
redisTemplate.delete(Arrays.asList(keys));
}
/**
* 指定字符模糊匹配批量删除keys
*/
public void deleteKeysByString(String str) {
Set<String> keys = redisTemplate.keys(str.concat("*"));
// 删除所有匹配的key
if (keys != null && !keys.isEmpty()) {
redisTemplate.delete(keys);
}
}
/**
* 获取key对应的字符数据