优化国标设备的Redis缓存策略
parent
7abafef230
commit
193f80963d
|
@ -16,7 +16,7 @@ public class VideoManagerConstants {
|
||||||
|
|
||||||
public static final String ONLINE_MEDIA_SERVERS_PREFIX = "VMP_ONLINE_MEDIA_SERVERS:";
|
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";
|
public static final String INVITE_PREFIX = "VMP_INVITE_INFO";
|
||||||
|
|
||||||
|
|
|
@ -173,46 +173,39 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(Device device) {
|
public void updateDevice(Device device) {
|
||||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + device.getDeviceId();
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
|
||||||
redisTemplate.opsForValue().set(key, device);
|
redisTemplate.opsForHash().put(key, device.getDeviceId(), device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeDevice(String deviceId) {
|
public void removeDevice(String deviceId) {
|
||||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
|
||||||
redisTemplate.delete(key);
|
redisTemplate.opsForHash().delete(key, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllDevice() {
|
public void removeAllDevice() {
|
||||||
String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
|
||||||
List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
|
|
||||||
for (Object key : keys) {
|
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getAllDevices() {
|
public List<Device> getAllDevices() {
|
||||||
String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
|
||||||
List<Device> result = new ArrayList<>();
|
List<Device> 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;
|
if (Objects.nonNull(value)) {
|
||||||
Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
|
result.add((Device)value);
|
||||||
if (Objects.nonNull(device)) {
|
|
||||||
// 只取没有存过得
|
|
||||||
result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(String deviceId) {
|
public Device getDevice(String deviceId) {
|
||||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId();
|
||||||
Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
|
Device device = (Device)redisTemplate.opsForHash().get(key, deviceId);
|
||||||
if (device == null){
|
if (device == null){
|
||||||
device = deviceMapper.getDeviceByDeviceId(deviceId);
|
device = deviceMapper.getDeviceByDeviceId(deviceId);
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
|
|
Loading…
Reference in New Issue