更新redis的使用和数据汇总性能优化
This commit is contained in:
@@ -23,7 +23,7 @@ public class RedisAspect {
|
||||
/**
|
||||
* 是否开启redis缓存 true开启 false关闭
|
||||
*/
|
||||
@Value("${weather.redis.open: false}")
|
||||
@Value("${project-options.redis.open: false}")
|
||||
private boolean open;
|
||||
|
||||
@Around("execution(* com.weather.common.redis.RedisUtils.*(..))")
|
||||
|
||||
@@ -55,4 +55,18 @@ public class RedisKeys {
|
||||
public static String getUserPermissionsKey(Long userId){
|
||||
return "sys:user:permissions:" + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 天气汇总缓存Key(按站点分组,月-日维度)
|
||||
*/
|
||||
public static String getWeatherSummarizeKey(int month, int day) {
|
||||
return "weather:summarize:" + month + ":" + day;
|
||||
}
|
||||
|
||||
/**
|
||||
* 天气汇总缓存匹配模式
|
||||
*/
|
||||
public static String getWeatherSummarizePattern() {
|
||||
return "weather:summarize:*";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +116,23 @@ public class RedisUtils {
|
||||
public Object rightPop(String key) {
|
||||
return redisTemplate.opsForList().rightPop(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按模式删除缓存
|
||||
* @param pattern 匹配模式,如 "weather:summarize:*"
|
||||
*/
|
||||
public void deleteByPattern(String pattern) {
|
||||
java.util.Set<String> keys = redisTemplate.keys(pattern);
|
||||
if (keys != null && !keys.isEmpty()) {
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断缓存是否存在
|
||||
*/
|
||||
public boolean exists(String key) {
|
||||
Boolean result = redisTemplate.hasKey(key);
|
||||
return Boolean.TRUE.equals(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user