bugfix redis获取数据报错

This commit is contained in:
Lemon
2026-01-07 14:59:51 +08:00
parent 9fa6f1fcb8
commit 84140e94a5
2 changed files with 62 additions and 10 deletions

View File

@@ -6412,10 +6412,24 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
redisKeys.add(CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + transactionCode);
}
// 批量查询多个key值的数据 key: redisKey, value: 最后一条实时数据
Map<String, RealTimeMonitorData> map = redisCache.multiGetLastListValue(redisKeys);
// 循环该map
for (Map.Entry<String, RealTimeMonitorData> entry : map.entrySet()) {
resultList.add(entry.getValue());
// 注意数据在Redis中以Hash类型存储field为时间字符串需要获取所有field后取最新的一条
for (String redisKey : redisKeys) {
try {
Map<String, String> hashData = redisCache.getCacheMap(redisKey);
if (hashData != null && !hashData.isEmpty()) {
// 按时间排序,获取最新的一条数据
String latestJson = hashData.entrySet().stream()
.max(Map.Entry.comparingByKey())
.map(Map.Entry::getValue)
.orElse(null);
if (latestJson != null) {
RealTimeMonitorData data = JSON.parseObject(latestJson, RealTimeMonitorData.class);
resultList.add(data);
}
}
} catch (Exception e) {
logger.error("获取实时监控数据失败redisKey={}", redisKey, e);
}
}
return resultList;
}