优化GPS内容的REDIS缓存存取

pull/1669/head
648540858 2024-10-28 09:19:49 +08:00
parent 296cf1e3fe
commit 183d87b9b6
1 changed files with 9 additions and 13 deletions

View File

@ -209,31 +209,27 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId(); String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId();
Duration duration = Duration.ofSeconds(60L); Duration duration = Duration.ofSeconds(60L);
redisTemplate.opsForValue().set(key, gpsMsgInfo, duration); redisTemplate.opsForHash().put(key, gpsMsgInfo.getId(),gpsMsgInfo);
redisTemplate.expire(key, duration);
// 默认GPS消息保存1分钟 // 默认GPS消息保存1分钟
} }
@Override @Override
public GPSMsgInfo getGpsMsgInfo(String channelId) { public GPSMsgInfo getGpsMsgInfo(String channelId) {
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + channelId; String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId();
return JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class); return (GPSMsgInfo) redisTemplate.opsForHash().get(key, channelId);
} }
@Override @Override
public List<GPSMsgInfo> getAllGpsMsgInfo() { public List<GPSMsgInfo> getAllGpsMsgInfo() {
String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_*"; String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId();
List<GPSMsgInfo> result = new ArrayList<>(); List<GPSMsgInfo> result = new ArrayList<>();
List<Object> keys = RedisUtil.scan(redisTemplate, scanKey); List<Object> values = redisTemplate.opsForHash().values(key);
for (Object o : keys) { for (Object value : values) {
String key = (String) o; result.add((GPSMsgInfo)value);
GPSMsgInfo gpsMsgInfo = JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class);
if (Objects.nonNull(gpsMsgInfo) && !gpsMsgInfo.isStored()) { // 只取没有存过得
result.add(JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class));
}
} }
return result; return result;
} }