1
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user