优化媒体节点的Redis缓存策略
parent
b3debde31b
commit
7abafef230
|
@ -12,7 +12,7 @@ public class VideoManagerConstants {
|
||||||
|
|
||||||
public static final String WVP_SERVER_STREAM_PREFIX = "VMP_SIGNALLING_STREAM_";
|
public static final String WVP_SERVER_STREAM_PREFIX = "VMP_SIGNALLING_STREAM_";
|
||||||
|
|
||||||
public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER:";
|
public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_INFO:";
|
||||||
|
|
||||||
public static final String ONLINE_MEDIA_SERVERS_PREFIX = "VMP_ONLINE_MEDIA_SERVERS:";
|
public static final String ONLINE_MEDIA_SERVERS_PREFIX = "VMP_ONLINE_MEDIA_SERVERS:";
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
||||||
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
|
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
|
||||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||||
import com.genersoft.iot.vmp.utils.JsonUtil;
|
|
||||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
|
||||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -153,10 +151,10 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
ssrcFactory.initMediaServerSSRC(mediaServer.getId(), null);
|
ssrcFactory.initMediaServerSSRC(mediaServer.getId(), null);
|
||||||
}
|
}
|
||||||
// 查询redis是否存在此mediaServer
|
// 查询redis是否存在此mediaServer
|
||||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + ":" + mediaServer.getId();
|
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId();
|
||||||
Boolean hasKey = redisTemplate.hasKey(key);
|
Boolean hasKey = redisTemplate.hasKey(key);
|
||||||
if (hasKey != null && !hasKey) {
|
if (hasKey != null && !hasKey) {
|
||||||
redisTemplate.opsForValue().set(key, mediaServer);
|
redisTemplate.opsForHash().put(key, mediaServer.getId(), mediaServer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,8 +303,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
if (mediaServerInRedis == null || !ssrcFactory.hasMediaServerSSRC(mediaServerInDataBase.getId())) {
|
if (mediaServerInRedis == null || !ssrcFactory.hasMediaServerSSRC(mediaServerInDataBase.getId())) {
|
||||||
ssrcFactory.initMediaServerSSRC(mediaServerInDataBase.getId(),null);
|
ssrcFactory.initMediaServerSSRC(mediaServerInDataBase.getId(),null);
|
||||||
}
|
}
|
||||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + ":" + mediaServerInDataBase.getId();
|
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId();
|
||||||
redisTemplate.opsForValue().set(key, mediaServerInDataBase);
|
redisTemplate.opsForHash().put(key, mediaServerInDataBase.getId(), mediaServerInDataBase);
|
||||||
if (mediaServerInDataBase.isStatus()) {
|
if (mediaServerInDataBase.isStatus()) {
|
||||||
resetOnlineServerItem(mediaServerInDataBase);
|
resetOnlineServerItem(mediaServerInDataBase);
|
||||||
}else {
|
}else {
|
||||||
|
@ -321,14 +319,14 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
@Override
|
@Override
|
||||||
public List<MediaServer> getAllOnlineList() {
|
public List<MediaServer> getAllOnlineList() {
|
||||||
List<MediaServer> result = new ArrayList<>();
|
List<MediaServer> result = new ArrayList<>();
|
||||||
List<Object> mediaServerKeys = RedisUtil.scan(redisTemplate, String.format("%S*", VideoManagerConstants.MEDIA_SERVER_PREFIX+ userSetting.getServerId() + ":" ));
|
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId();
|
||||||
String onlineKey = VideoManagerConstants.ONLINE_MEDIA_SERVERS_PREFIX + userSetting.getServerId();
|
String onlineKey = VideoManagerConstants.ONLINE_MEDIA_SERVERS_PREFIX + userSetting.getServerId();
|
||||||
for (Object mediaServerKey : mediaServerKeys) {
|
List<Object> values = redisTemplate.opsForHash().values(key);
|
||||||
String key = (String) mediaServerKey;
|
for (Object value : values) {
|
||||||
MediaServer mediaServer = JsonUtil.redisJsonToObject(redisTemplate, key, MediaServer.class);
|
if (Objects.isNull(value)) {
|
||||||
if (Objects.isNull(mediaServer)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
MediaServer mediaServer = (MediaServer) value;
|
||||||
// 检查状态
|
// 检查状态
|
||||||
Double aDouble = redisTemplate.opsForZSet().score(onlineKey, mediaServer.getId());
|
Double aDouble = redisTemplate.opsForZSet().score(onlineKey, mediaServer.getId());
|
||||||
if (aDouble != null) {
|
if (aDouble != null) {
|
||||||
|
@ -377,8 +375,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
if (mediaServerIdSet != null && !mediaServerIdSet.isEmpty()) {
|
if (mediaServerIdSet != null && !mediaServerIdSet.isEmpty()) {
|
||||||
for (Object mediaServerId : mediaServerIdSet) {
|
for (Object mediaServerId : mediaServerIdSet) {
|
||||||
String mediaServerIdStr = (String) mediaServerId;
|
String mediaServerIdStr = (String) mediaServerId;
|
||||||
String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + ":" + mediaServerIdStr;
|
String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId();
|
||||||
result.add((MediaServer) redisTemplate.opsForValue().get(serverKey));
|
result.add((MediaServer) redisTemplate.opsForHash().get(serverKey, mediaServerIdStr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.reverse(result);
|
Collections.reverse(result);
|
||||||
|
@ -395,8 +393,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
if (mediaServerId == null) {
|
if (mediaServerId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + ":" + mediaServerId;
|
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId();
|
||||||
return JsonUtil.redisJsonToObject(redisTemplate, key, MediaServer.class);
|
return (MediaServer) redisTemplate.opsForHash().get(key, mediaServerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue