1
This commit is contained in:
@@ -388,9 +388,18 @@ public class JDInnerController {
|
||||
* 手动清理Redis中超过93天的旧数据
|
||||
* 请求参数:{ skey }
|
||||
* 返回:{ message, success }
|
||||
* 注意:请将skey放在请求Body中(JSON格式),不是Query参数
|
||||
*/
|
||||
@PostMapping("/cleanRedisData")
|
||||
public Object cleanRedisData(@RequestBody Map<String, Object> body) {
|
||||
public Object cleanRedisData(@RequestBody(required = false) Map<String, Object> body) {
|
||||
// 兼容处理:如果body为空,返回友好提示
|
||||
if (body == null || body.isEmpty()) {
|
||||
JSONObject tips = new JSONObject();
|
||||
tips.put("error", "请求Body不能为空");
|
||||
tips.put("tip", "请在Postman的Body标签中选择raw/JSON格式,并输入: {\"skey\": \"your_skey_here\"}");
|
||||
return tips;
|
||||
}
|
||||
|
||||
String skey = body.get("skey") != null ? String.valueOf(body.get("skey")) : null;
|
||||
if (checkSkey(skey)) {
|
||||
return error("invalid skey");
|
||||
|
||||
@@ -610,24 +610,15 @@ public void cleanOldRedisHashData() {
|
||||
// 2. jd:refresh:tag:2024-11-30 09:26:00
|
||||
String timePart;
|
||||
|
||||
// 检查是否包含hash值(32位十六进制字符串)
|
||||
if (key.matches("jd:refresh:tag:[a-f0-9]{32}:[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")) {
|
||||
// 格式:jd:refresh:tag:hash值:时间
|
||||
timePart = key.substring(key.lastIndexOf(":") + 1);
|
||||
} else if (key.matches("jd:refresh:tag:[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")) {
|
||||
// 格式:jd:refresh:tag:时间
|
||||
timePart = key.substring("jd:refresh:tag:".length());
|
||||
// 使用正则表达式统一提取时间部分(避免lastIndexOf在时间字符串中找到错误的冒号)
|
||||
String timePattern = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
|
||||
Pattern pattern = Pattern.compile(timePattern);
|
||||
Matcher matcher = pattern.matcher(key);
|
||||
if (matcher.find()) {
|
||||
timePart = matcher.group();
|
||||
} else {
|
||||
// 尝试更宽松的匹配,查找时间模式
|
||||
String timePattern = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
|
||||
Pattern pattern = Pattern.compile(timePattern);
|
||||
Matcher matcher = pattern.matcher(key);
|
||||
if (matcher.find()) {
|
||||
timePart = matcher.group();
|
||||
} else {
|
||||
logger.warn("无法识别Redis键格式:{}", key);
|
||||
continue;
|
||||
}
|
||||
logger.warn("无法识别Redis键格式:{}", key);
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalDateTime time;
|
||||
|
||||
Reference in New Issue
Block a user