优化国标设备的Redis缓存策略

pull/1669/head
648540858 2024-10-24 18:32:37 +08:00
parent 7abafef230
commit 193f80963d
2 changed files with 14 additions and 21 deletions

View File

@ -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";

View File

@ -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<Object> 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<Device> getAllDevices() {
String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
List<Device> result = new ArrayList<>();
List<Object> 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<Object> 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) {