From 193f80963d4432821864e2133f996082b2b25031 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 24 Oct 2024 18:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BD=E6=A0=87=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=9A=84Redis=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/common/VideoManagerConstants.java | 2 +- .../storager/impl/RedisCatchStorageImpl.java | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java index 0cc57194..cdf1123c 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java +++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java @@ -16,7 +16,7 @@ public class VideoManagerConstants { public static final String ONLINE_MEDIA_SERVERS_PREFIX = "VMP_ONLINE_MEDIA_SERVERS:"; - public static final String DEVICE_PREFIX = "VMP_DEVICE_"; + public static final String DEVICE_PREFIX = "VMP_DEVICE:"; public static final String INVITE_PREFIX = "VMP_INVITE_INFO"; 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 3418525d..2386edec 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 @@ -173,46 +173,39 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @Override public void updateDevice(Device device) { - String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + device.getDeviceId(); - redisTemplate.opsForValue().set(key, device); + String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId(); + redisTemplate.opsForHash().put(key, device.getDeviceId(), device); } @Override public void removeDevice(String deviceId) { - String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId; - redisTemplate.delete(key); + String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId(); + redisTemplate.opsForHash().delete(key, deviceId); } @Override public void removeAllDevice() { - String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*"; - List keys = RedisUtil.scan(redisTemplate, scanKey); - for (Object key : keys) { - redisTemplate.delete(key); - } + String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId(); + redisTemplate.delete(key); } @Override public List getAllDevices() { - String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*"; + String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId(); List result = new ArrayList<>(); - List keys = RedisUtil.scan(redisTemplate, scanKey); - for (Object o : keys) { - String key = (String) o; - Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); - if (Objects.nonNull(device)) { - // 只取没有存过得 - result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class)); + List values = redisTemplate.opsForHash().values(key); + for (Object value : values) { + if (Objects.nonNull(value)) { + result.add((Device)value); } } - return result; } @Override public Device getDevice(String deviceId) { - String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId; - Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); + String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId(); + Device device = (Device)redisTemplate.opsForHash().get(key, deviceId); if (device == null){ device = deviceMapper.getDeviceByDeviceId(deviceId); if (device != null) {