From 6fc8db8bd04c87b2a8d79c9199fa552f76055dd1 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 25 Oct 2024 18:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96INVITE=E4=BA=8B=E5=8A=A1REDIS?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=AD=98=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/common/VideoManagerConstants.java | 2 +- .../session/SipInviteSessionManager.java | 51 ++++++++----------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java index 33f5f0ca..09fe7c4d 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java +++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java @@ -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_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_STREAM = SIP_INVITE_SESSION + "STREAM:"; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SipInviteSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SipInviteSessionManager.java index 5ef6a953..3a3bdaef 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SipInviteSessionManager.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SipInviteSessionManager.java @@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.gb28181.session; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.UserSetting; 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.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -27,39 +26,34 @@ public class SipInviteSessionManager { * 添加一个点播/回放的事务信息 */ public void put(SsrcTransaction ssrcTransaction){ - redisTemplate.opsForValue().set(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() - + ":" + ssrcTransaction.getStream(), ssrcTransaction); + redisTemplate.opsForHash().put(VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() + , ssrcTransaction.getStream(), ssrcTransaction); - redisTemplate.opsForValue().set(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() - + ":" + ssrcTransaction.getCallId(), ssrcTransaction); + redisTemplate.opsForHash().put(VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + , ssrcTransaction.getCallId(), ssrcTransaction); } public SsrcTransaction getSsrcTransactionByStream(String stream){ - String key = VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId() + ":" + stream; - return (SsrcTransaction)redisTemplate.opsForValue().get(key); + String key = VideoManagerConstants.SIP_INVITE_SESSION_STREAM + userSetting.getServerId(); + return (SsrcTransaction)redisTemplate.opsForHash().get(key, stream); } public SsrcTransaction getSsrcTransactionByCallId(String callId){ - String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":" + callId; - return (SsrcTransaction)redisTemplate.opsForValue().get(key); + String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId(); + return (SsrcTransaction)redisTemplate.opsForHash().get(key, callId); } public List getSsrcTransactionByDeviceId(String deviceId){ - String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":*"; - - List scanResult = RedisUtil.scan(redisTemplate, key); - if (scanResult.isEmpty()) { - return new ArrayList<>(); - } + String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId(); + List values = redisTemplate.opsForHash().values(key); List result = new ArrayList<>(); - for (Object keyObj : scanResult) { - SsrcTransaction ssrcTransaction = (SsrcTransaction)redisTemplate.opsForValue().get(keyObj); + for (Object value : values) { + SsrcTransaction ssrcTransaction = (SsrcTransaction) value; if (ssrcTransaction != null && deviceId.equals(ssrcTransaction.getDeviceId())) { result.add(ssrcTransaction); } } return result; - } public void removeByStream(String stream) { @@ -67,9 +61,9 @@ public class SipInviteSessionManager { if (ssrcTransaction == null ) { 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) { - 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 ) { 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) { - 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 getAll() { - String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId() + ":*"; - - List scanResult = RedisUtil.scan(redisTemplate, key); - if (scanResult.isEmpty()) { - return new ArrayList<>(); - } + String key = VideoManagerConstants.SIP_INVITE_SESSION_CALL_ID + userSetting.getServerId(); + List values = redisTemplate.opsForHash().values(key); List result = new ArrayList<>(); - for (Object keyObj : scanResult) { - SsrcTransaction ssrcTransaction = (SsrcTransaction)redisTemplate.opsForValue().get(keyObj); - result.add(ssrcTransaction); + for (Object value : values) { + result.add((SsrcTransaction) value); } return result; }