This commit is contained in:
雷欧(林平凡)
2025-10-11 16:14:40 +08:00
parent dba361bed3
commit 7a2b9a2182

View File

@@ -98,7 +98,7 @@ public class InstructionServiceImpl implements IInstructionService {
// 从左边推入消息(新消息在前) // 从左边推入消息(新消息在前)
stringRedisTemplate.opsForList().leftPush(key, timestampedMessage); stringRedisTemplate.opsForList().leftPush(key, timestampedMessage);
// 保持列表最多100条删除最早的消息 // 保持列表最多100条删除最早的消息
stringRedisTemplate.opsForList().trim(key, 0, 99); stringRedisTemplate.opsForList().trim(key, 0, 999);
} catch (Exception e) { } catch (Exception e) {
// 记录异常但不影响主流程 // 记录异常但不影响主流程
System.err.println("存储消息到Redis失败: " + e.getMessage()); System.err.println("存储消息到Redis失败: " + e.getMessage());
@@ -123,7 +123,7 @@ public class InstructionServiceImpl implements IInstructionService {
} }
// 确定获取数量默认100条 // 确定获取数量默认100条
int count = (limit != null && limit > 0) ? Math.min(limit, 100) : 100; int count = (limit != null && limit > 0) ? Math.min(limit, 1000) : 1000;
// 从Redis获取历史消息索引0到count-1 // 从Redis获取历史消息索引0到count-1
List<String> messages = stringRedisTemplate.opsForList().range(key, 0, count - 1); List<String> messages = stringRedisTemplate.opsForList().range(key, 0, count - 1);