This commit is contained in:
CC
2025-10-28 00:33:26 +08:00
parent 1c9c9cfa06
commit a82ff0d39f
3 changed files with 32 additions and 22 deletions
+14 -4
View File
@@ -9,11 +9,15 @@
### 方式一:手动调用API接口(推荐)
发送POST请求到:`http://your-server:port/jd/cleanRedisData`
⚠️ **注意端口号**:
- **jd项目端口**:6666(直接访问,无需认证)
- RuoYi框架端口:30313(需要认证,不推荐)
发送POST请求到:`http://your-server:6666/jd/cleanRedisData`
**请求示例:**
```bash
curl -X POST http://localhost:8080/jd/cleanRedisData \
curl -X POST http://192.168.8.88:6666/jd/cleanRedisData \
-H "Content-Type: application/json" \
-d '{
"skey": "2192057370ef8140c201079969c956a3"
@@ -31,15 +35,21 @@ curl -X POST http://localhost:8080/jd/cleanRedisData \
### 方式二:使用Postman等工具
1. 创建新的POST请求
2. URL: `http://localhost:8080/jd/cleanRedisData`
2. URL: `http://192.168.8.88:6666/jd/cleanRedisData`(注意是6666端口)
3. Headers: `Content-Type: application/json`
4. Body (raw JSON):
4. Body 标签选择 **raw** 格式,类型选择 **JSON**
5. Body 内容:
```json
{
"skey": "2192057370ef8140c201079969c956a3"
}
```
⚠️ **常见错误**:
- ❌ 不要把skey放在Query参数中
- ❌ 不要使用30313端口(会遇到401认证错误)
- ✅ 确保在Body标签中使用JSON格式
### 方式三:自动定时执行
系统已配置定时任务,每天凌晨3点自动执行清理:
@@ -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;