优化部分redis scan查询

pull/1653/head
648540858 2024-10-21 17:42:26 +08:00
parent 9506bef6cb
commit 189e56c839
5 changed files with 43 additions and 64 deletions

View File

@ -18,18 +18,7 @@ public class VideoManagerConstants {
public static final String DEVICE_PREFIX = "VMP_DEVICE_";
// 设备同步完成
public static final String DEVICE_SYNC_PREFIX = "VMP_DEVICE_SYNC_";
public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_";
public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_";
// TODO 此处多了一个_暂不修改
public static final String INVITE_PREFIX = "VMP_INVITE_INFO";
public static final String PLAYER_PREFIX = "VMP_INVITE_PLAY_";
public static final String PLAY_BLACK_PREFIX = "VMP_INVITE_PLAYBACK_";
public static final String DOWNLOAD_PREFIX = "VMP_INVITE_DOWNLOAD_";
public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_";
@ -40,30 +29,18 @@ public class VideoManagerConstants {
public static final String PLATFORM_REGISTER_INFO_PREFIX = "VMP_PLATFORM_REGISTER_INFO_";
public static final String SEND_RTP_INFO = "VMP_SEND_RTP_INFO:";
public static final String SEND_RTP_INFO_CALLID = "VMP_SEND_RTP_INFO:CALL_ID";
public static final String SEND_RTP_INFO_STREAM = "VMP_SEND_RTP_INFO:STREAM";
public static final String SEND_RTP_INFO_CHANNEL = "VMP_SEND_RTP_INFO:CHANNEL";
public static final String EVENT_ONLINE_REGISTER = "1";
public static final String EVENT_ONLINE_MESSAGE = "3";
public static final String EVENT_OUTLINE_UNREGISTER = "1";
public static final String EVENT_OUTLINE_TIMEOUT = "2";
public static final String MEDIA_SSRC_USED_PREFIX = "VMP_MEDIA_USED_SSRC_";
public static final String SEND_RTP_INFO_CALLID = "VMP_SEND_RTP_INFO:CALL_ID:";
public static final String SEND_RTP_INFO_STREAM = "VMP_SEND_RTP_INFO:STREAM:";
public static final String SEND_RTP_INFO_CHANNEL = "VMP_SEND_RTP_INFO:CHANNEL:";
public static final String SIP_INVITE_SESSION = "VMP_SIP_INVITE_SESSION:";
public static final String SIP_INVITE_SESSION_CALL_ID = SIP_INVITE_SESSION + "CALL_ID" + ":";
public static final String SIP_INVITE_SESSION_STREAM = SIP_INVITE_SESSION + "STREAM" + ":";
public static final String SIP_INVITE_SESSION_CALL_ID = SIP_INVITE_SESSION + "CALL_ID:";
public static final String SIP_INVITE_SESSION_STREAM = SIP_INVITE_SESSION + "STREAM:";
public static final String MEDIA_STREAM_AUTHORITY = "VMP_MEDIA_STREAM_AUTHORITY_";
public static final String SIP_CSEQ_PREFIX = "VMP_SIP_CSEQ_";
public static final String SIP_SN_PREFIX = "VMP_SIP_SN_";
public static final String SIP_SUBSCRIBE_PREFIX = "VMP_SIP_SUBSCRIBE_";
public static final String SYSTEM_INFO_CPU_PREFIX = "VMP_SYSTEM_INFO_CPU_";
@ -79,7 +56,6 @@ public class VideoManagerConstants {
public static final String PUSH_STREAM_LIST = "VMP_PUSH_STREAM_LIST_";
public static final String WAITE_SEND_PUSH_STREAM = "VMP_WAITE_SEND_PUSH_STREAM:";
public static final String START_SEND_PUSH_STREAM = "VMP_START_SEND_PUSH_STREAM:";
public static final String PUSH_STREAM_ONLINE = "VMP_PUSH_STREAM_ONLINE:";

View File

@ -79,10 +79,8 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
InviteInfo inviteInfoForUpdate;
if (InviteSessionStatus.ready == inviteInfo.getStatus()) {
if (inviteInfo.getDeviceId() == null
|| inviteInfo.getChannelId() == null
|| inviteInfo.getType() == null
|| inviteInfo.getStream() == null
if (inviteInfo.getDeviceId() == null || inviteInfo.getChannelId() == null
|| inviteInfo.getType() == null || inviteInfo.getStream() == null
) {
return;
}
@ -118,7 +116,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
}
String key = VideoManagerConstants.INVITE_PREFIX +
":" + inviteInfoForUpdate.getType() +
":" + inviteInfoForUpdate.getDeviceId() +
":" + inviteInfoForUpdate.getChannelId() +
":" + inviteInfoForUpdate.getStream()+
":" + inviteInfoForUpdate.getSsrcInfo().getSsrc();
@ -139,7 +136,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
removeInviteInfo(inviteInfoInDb);
String key = VideoManagerConstants.INVITE_PREFIX +
":" + inviteInfo.getType() +
":" + inviteInfo.getDeviceId() +
":" + inviteInfo.getChannelId() +
":" + stream +
":" + inviteInfo.getSsrcInfo().getSsrc();
@ -160,7 +156,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
public InviteInfo getInviteInfo(InviteSessionType type, Integer channelId, String stream) {
String key = VideoManagerConstants.INVITE_PREFIX +
":" + (type != null ? type : "*") +
":*" +
":" + (channelId != null ? channelId : "*") +
":" + (stream != null ? stream : "*")
+ ":*";
@ -179,7 +174,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
public List<InviteInfo> getAllInviteInfo(InviteSessionType type, Integer channelId, String stream) {
String key = VideoManagerConstants.INVITE_PREFIX +
":" + (type != null ? type : "*") +
":*" +
":" + (channelId != null ? channelId : "*") +
":" + (stream != null ? stream : "*")
+ ":*";
@ -208,7 +202,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
public void removeInviteInfo(InviteSessionType type, Integer channelId, String stream) {
String scanKey = VideoManagerConstants.INVITE_PREFIX +
":" + (type != null ? type : "*") +
":*" +
":" + (channelId != null ? channelId : "*") +
":" + (stream != null ? stream : "*") +
":*";
@ -267,7 +260,7 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
@Override
public int getStreamInfoCount(String mediaServerId) {
int count = 0;
String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*:*";
String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*";
List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
if (scanResult.isEmpty()) {
return 0;
@ -316,7 +309,7 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
@Override
public InviteInfo getInviteInfoBySSRC(String ssrc) {
String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*:" + ssrc;
String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:" + ssrc;
List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
if (scanResult.size() != 1) {
return null;
@ -334,7 +327,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
removeInviteInfo(inviteInfoInDb);
String key = VideoManagerConstants.INVITE_PREFIX +
":" + inviteInfo.getType() +
":" + inviteInfo.getDeviceId() +
":" + inviteInfo.getChannelId() +
":" + inviteInfo.getStream() +
":" + ssrc;

View File

@ -65,14 +65,14 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Override
public void update(SendRtpInfo sendRtpItem) {
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpItem.getCallId(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream() + ":" + sendRtpItem.getTargetId(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId() + ":" + sendRtpItem.getTargetId(), sendRtpItem);
redisTemplate.opsForHash().put(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream(), sendRtpItem.getTargetId(), sendRtpItem);
redisTemplate.opsForHash().put(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId(), sendRtpItem.getTargetId(), sendRtpItem);
}
@Override
public SendRtpInfo queryByChannelId(Integer channelId, String targetId) {
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":" + targetId;
return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class);
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId;
return JsonUtil.redisHashJsonToObject(redisTemplate, key, targetId, SendRtpInfo.class);
}
@Override
@ -83,19 +83,17 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Override
public SendRtpInfo queryByStream(String stream, String targetId) {
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":" + targetId;
return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class);
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream;
return JsonUtil.redisHashJsonToObject(redisTemplate, key, targetId, SendRtpInfo.class);
}
@Override
public List<SendRtpInfo> queryByStream(String stream) {
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":*";
List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream;
List<Object> values = redisTemplate.opsForHash().values(key);
List<SendRtpInfo> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem));
for (Object o : values) {
result.add((SendRtpInfo) o);
}
return result;
@ -110,8 +108,16 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
return;
}
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpInfo.getCallId());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream() + ":" + sendRtpInfo.getTargetId());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId() + ":" + sendRtpInfo.getTargetId());
if (redisTemplate.opsForHash().size(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream()) == 0) {
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream());
}else {
redisTemplate.opsForHash().delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream(), sendRtpInfo.getTargetId());
}
if (redisTemplate.opsForHash().size(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId()) == 0) {
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId());
}else {
redisTemplate.opsForHash().delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId(), sendRtpInfo.getTargetId());
}
}
@Override
public void deleteByCallId(String callId) {
@ -149,22 +155,18 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Override
public List<SendRtpInfo> queryByChannelId(int channelId) {
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":*";
List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId;
List<Object> values = redisTemplate.opsForHash().values(key);
List<SendRtpInfo> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem));
for (Object o : values) {
result.add((SendRtpInfo) o);
}
return result;
}
@Override
public List<SendRtpInfo> queryAll() {
String key = VideoManagerConstants.SEND_RTP_INFO_CALLID
+ userSetting.getServerId() + ":*";
String key = VideoManagerConstants.SEND_RTP_INFO_CALLID + ":*";
List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
List<SendRtpInfo> result= new ArrayList<>();

View File

@ -98,6 +98,7 @@ public interface IRedisCatchStorage {
void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo);
GPSMsgInfo getGpsMsgInfo(String gbId);
List<GPSMsgInfo> getAllGpsMsgInfo();
MediaInfo getStreamInfo(String app, String streamId, String mediaServerId);

View File

@ -31,4 +31,12 @@ public final class JsonUtil {
}
return clazz.cast(jsonObject);
}
public static <T> T redisHashJsonToObject(RedisTemplate<Object, Object> redisTemplate, String key, String objKey, Class<T> clazz) {
Object jsonObject = redisTemplate.opsForHash().get(key, objKey);
if (Objects.isNull(jsonObject)) {
return null;
}
return clazz.cast(jsonObject);
}
}