This commit is contained in:
2025-10-15 00:57:37 +08:00

View File

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