From 183d87b9b64e84757f8667c7c538673a7c89b363 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 28 Oct 2024 09:19:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96GPS=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=9A=84REDIS=E7=BC=93=E5=AD=98=E5=AD=98=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storager/impl/RedisCatchStorageImpl.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index b5307c44..be73a17c 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -209,31 +209,27 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @Override 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); - redisTemplate.opsForValue().set(key, gpsMsgInfo, duration); + redisTemplate.opsForHash().put(key, gpsMsgInfo.getId(),gpsMsgInfo); + redisTemplate.expire(key, duration); // 默认GPS消息保存1分钟 } @Override public GPSMsgInfo getGpsMsgInfo(String channelId) { - String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + channelId; - return JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class); + String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId(); + return (GPSMsgInfo) redisTemplate.opsForHash().get(key, channelId); } @Override public List getAllGpsMsgInfo() { - String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_*"; + String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId(); List result = new ArrayList<>(); - List keys = RedisUtil.scan(redisTemplate, scanKey); - for (Object o : keys) { - String key = (String) o; - GPSMsgInfo gpsMsgInfo = JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class); - if (Objects.nonNull(gpsMsgInfo) && !gpsMsgInfo.isStored()) { // 只取没有存过得 - result.add(JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class)); - } + List values = redisTemplate.opsForHash().values(key); + for (Object value : values) { + result.add((GPSMsgInfo)value); } - return result; }