优化INVITE事务REDIS缓存存取
parent
059635c2cc
commit
6fc8db8bd0
|
@ -29,7 +29,7 @@ public class VideoManagerConstants {
|
||||||
public static final String SEND_RTP_INFO_STREAM = "VMP_SEND_RTP_INFO:STREAM:";
|
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 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 = "VMP_SIP_INVITE_SESSION_INFO:";
|
||||||
public static final String SIP_INVITE_SESSION_CALL_ID = SIP_INVITE_SESSION + "CALL_ID:";
|
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_STREAM = SIP_INVITE_SESSION + "STREAM:";
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.gb28181.session;
|
||||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -27,39 +26,34 @@ public class SipInviteSessionManager {
|
||||||
* 添加一个点播/回放的事务信息
|
* 添加一个点播/回放的事务信息
|
||||||
*/
|
*/
|
||||||
public void put(SsrcTransaction ssrcTransaction){
|
public void put(SsrcTransaction ssrcTransaction){
|
||||||
redisTemplate.opsForValue().set(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId()
|
redisTemplate.opsForHash().put(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId()
|
||||||
+ ":" + ssrcTransaction.getStream(), ssrcTransaction);
|
, ssrcTransaction.getStream(), ssrcTransaction);
|
||||||
|
|
||||||
redisTemplate.opsForValue().set(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId()
|
redisTemplate.opsForHash().put(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId()
|
||||||
+ ":" + ssrcTransaction.getCallId(), ssrcTransaction);
|
, ssrcTransaction.getCallId(), ssrcTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SsrcTransaction getSsrcTransactionByStream(String stream){
|
public SsrcTransaction getSsrcTransactionByStream(String stream){
|
||||||
String key = VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() + ":" + stream;
|
String key = VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId();
|
||||||
return (SsrcTransaction)redisTemplate.opsForValue().get(key);
|
return (SsrcTransaction)redisTemplate.opsForHash().get(key, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SsrcTransaction getSsrcTransactionByCallId(String callId){
|
public SsrcTransaction getSsrcTransactionByCallId(String callId){
|
||||||
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":" + callId;
|
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId();
|
||||||
return (SsrcTransaction)redisTemplate.opsForValue().get(key);
|
return (SsrcTransaction)redisTemplate.opsForHash().get(key, callId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SsrcTransaction> getSsrcTransactionByDeviceId(String deviceId){
|
public List<SsrcTransaction> getSsrcTransactionByDeviceId(String deviceId){
|
||||||
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":*";
|
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId();
|
||||||
|
List<Object> values = redisTemplate.opsForHash().values(key);
|
||||||
List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
|
|
||||||
if (scanResult.isEmpty()) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
List<SsrcTransaction> result = new ArrayList<>();
|
List<SsrcTransaction> result = new ArrayList<>();
|
||||||
for (Object keyObj : scanResult) {
|
for (Object value : values) {
|
||||||
SsrcTransaction ssrcTransaction = (SsrcTransaction)redisTemplate.opsForValue().get(keyObj);
|
SsrcTransaction ssrcTransaction = (SsrcTransaction) value;
|
||||||
if (ssrcTransaction != null && deviceId.equals(ssrcTransaction.getDeviceId())) {
|
if (ssrcTransaction != null && deviceId.equals(ssrcTransaction.getDeviceId())) {
|
||||||
result.add(ssrcTransaction);
|
result.add(ssrcTransaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeByStream(String stream) {
|
public void removeByStream(String stream) {
|
||||||
|
@ -67,9 +61,9 @@ public class SipInviteSessionManager {
|
||||||
if (ssrcTransaction == null ) {
|
if (ssrcTransaction == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
redisTemplate.delete(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() + ":" + stream);
|
redisTemplate.opsForHash().delete(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId(), stream);
|
||||||
if (ssrcTransaction.getCallId() != null) {
|
if (ssrcTransaction.getCallId() != null) {
|
||||||
redisTemplate.delete(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":" + ssrcTransaction.getCallId());
|
redisTemplate.opsForHash().delete(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId(), ssrcTransaction.getCallId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,23 +72,18 @@ public class SipInviteSessionManager {
|
||||||
if (ssrcTransaction == null ) {
|
if (ssrcTransaction == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
redisTemplate.delete(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":" + callId);
|
redisTemplate.opsForHash().delete(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId(), callId);
|
||||||
if (ssrcTransaction.getStream() != null) {
|
if (ssrcTransaction.getStream() != null) {
|
||||||
redisTemplate.delete(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() + ":" + ssrcTransaction.getStream());
|
redisTemplate.opsForHash().delete(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId(), ssrcTransaction.getStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SsrcTransaction> getAll() {
|
public List<SsrcTransaction> getAll() {
|
||||||
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":*";
|
String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId();
|
||||||
|
List<Object> values = redisTemplate.opsForHash().values(key);
|
||||||
List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
|
|
||||||
if (scanResult.isEmpty()) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
List<SsrcTransaction> result = new ArrayList<>();
|
List<SsrcTransaction> result = new ArrayList<>();
|
||||||
for (Object keyObj : scanResult) {
|
for (Object value : values) {
|
||||||
SsrcTransaction ssrcTransaction = (SsrcTransaction)redisTemplate.opsForValue().get(keyObj);
|
result.add((SsrcTransaction) value);
|
||||||
result.add(ssrcTransaction);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue