commit
f7e188f425
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>com.genersoft</groupId>
|
||||
<artifactId>wvp-pro</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<version>2.3.2</version>
|
||||
<name>web video platform</name>
|
||||
<description>国标28181视频平台</description>
|
||||
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
alter table stream_push
|
||||
add serverId varchar(50) not null;
|
||||
|
||||
alter table device
|
||||
add geoCoordSys varchar(50) not null;
|
||||
alter table device
|
||||
add treeType varchar(50) not null;
|
||||
update device set device.geoCoordSys='WGS84';
|
||||
update device set device.treeType='CivilCode';
|
||||
|
||||
alter table device_channel
|
||||
add longitudeGcj02 double default null;
|
||||
alter table device_channel
|
||||
add latitudeGcj02 double default null;
|
||||
alter table device_channel
|
||||
add longitudeWgs84 double default null;
|
||||
alter table device_channel
|
||||
add latitudeWgs84 double default null;
|
||||
alter table device_channel
|
||||
add businessGroupId varchar(50) default null;
|
||||
alter table device_channel
|
||||
add gpsTime varchar(50) default null;
|
||||
|
||||
|
||||
alter table device_mobile_position
|
||||
change cnLng longitudeGcj02 double default null;
|
||||
alter table device_mobile_position
|
||||
change cnLat latitudeGcj02 double default null;
|
||||
alter table device_mobile_position
|
||||
add longitudeWgs84 double default null;
|
||||
alter table device_mobile_position
|
||||
add latitudeWgs84 double default null;
|
||||
alter table device_mobile_position
|
||||
drop geodeticSystem;
|
||||
alter table device_mobile_position
|
||||
add createTime varchar(50) default null;
|
||||
|
||||
alter table device_alarm
|
||||
add createTime varchar(50) default null;
|
||||
|
||||
alter table gb_stream
|
||||
change createStamp createTime varchar(50) default null;
|
||||
|
||||
alter table parent_platform
|
||||
add createTime varchar(50) default null;
|
||||
alter table parent_platform
|
||||
add updateTime varchar(50) default null;
|
||||
|
||||
alter table stream_proxy
|
||||
add updateTime varchar(50) default null;
|
||||
|
||||
alter table stream_push
|
||||
add pushTime varchar(50) default null;
|
||||
alter table stream_push
|
||||
add status int DEFAULT NULL;
|
||||
alter table stream_push
|
||||
add updateTime varchar(50) default null;
|
||||
alter table stream_push
|
||||
add pushIng int DEFAULT NULL;
|
||||
alter table stream_push
|
||||
change createStamp createTime varchar(50) default null;
|
||||
|
||||
alter table gb_stream
|
||||
drop column status;
|
||||
|
||||
alter table user
|
||||
add pushKey varchar(50) default null;
|
||||
update user set pushKey='453df297a57a5a7438934sda801fc3' where id=1;
|
||||
|
||||
alter table parent_platform
|
||||
add treeType varchar(50) not null;
|
||||
update parent_platform set parent_platform.treeType='BusinessGroup';
|
||||
alter table parent_platform drop shareAllLiveStream;
|
||||
|
||||
alter table platform_catalog
|
||||
add civilCode varchar(50) default null;
|
||||
alter table platform_catalog
|
||||
add businessGroupId varchar(50) default null;
|
||||
|
||||
/********************* ADD ***************************/
|
||||
alter table stream_push
|
||||
add self int DEFAULT NULL;
|
||||
|
||||
|
|
@ -14,8 +14,6 @@ public class VideoManagerConstants {
|
|||
|
||||
public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_";
|
||||
|
||||
public static final String MEDIA_SERVER_KEEPALIVE_PREFIX = "VMP_MEDIA_SERVER_KEEPALIVE_";
|
||||
|
||||
public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS_";
|
||||
|
||||
public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.genersoft.iot.vmp.conf;
|
||||
package com.genersoft.iot.vmp.conf.redis;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
@ -0,0 +1,81 @@
|
|||
package com.genersoft.iot.vmp.gb28181.event.offline;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.redis.RedisKeyExpirationEventMessageListener;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
|
||||
/**
|
||||
* 设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件
|
||||
* @author swwheihei
|
||||
*/
|
||||
@Component
|
||||
public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEventMessageListener {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(KeepaliveTimeoutListenerForPlatform.class);
|
||||
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private SipSubscribe sipSubscribe;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) {
|
||||
super(listenerContainer, userSetting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监听失效的key
|
||||
* @param message
|
||||
* @param pattern
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
// 获取失效的key
|
||||
String expiredKey = message.toString();
|
||||
// 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线
|
||||
String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_";
|
||||
String PLATFORM_REGISTER_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_";
|
||||
String REGISTER_INFO_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_";
|
||||
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) {
|
||||
String platformGbId = expiredKey.substring(PLATFORM_KEEPLIVEKEY_PREFIX.length());
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGbId);
|
||||
if (platform != null) {
|
||||
publisher.platformKeepaliveExpireEventPublish(platformGbId);
|
||||
}
|
||||
}else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
|
||||
String platformGbId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGbId);
|
||||
if (platform != null) {
|
||||
publisher.platformRegisterCycleEventPublish(platformGbId);
|
||||
}
|
||||
}else if (expiredKey.startsWith(REGISTER_INFO_PREFIX)) {
|
||||
String callId = expiredKey.substring(REGISTER_INFO_PREFIX.length());
|
||||
if (sipSubscribe.getErrorSubscribe(callId) != null) {
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult();
|
||||
eventResult.callId = callId;
|
||||
eventResult.msg = "注册超时";
|
||||
eventResult.type = "register timeout";
|
||||
sipSubscribe.getErrorSubscribe(callId).response(eventResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -112,7 +112,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
|||
} else if ((status >= 100) && (status < 200)) {
|
||||
// 增加其它无需回复的响应,如101、180等
|
||||
} else {
|
||||
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/);
|
||||
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase());
|
||||
if (responseEvent.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) {
|
||||
CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);
|
||||
if (callIdHeader != null) {
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package com.genersoft.iot.vmp.media.zlm.event;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @description:设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月6日 上午11:35:46
|
||||
*/
|
||||
@Component
|
||||
public class ZLMKeepliveTimeoutListener extends RedisKeyExpirationEventMessageListener {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ZLMKeepliveTimeoutListener.class);
|
||||
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) {
|
||||
super(listenerContainer, userSetting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监听失效的key,key格式为keeplive_deviceId
|
||||
* @param message
|
||||
* @param pattern
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
// 获取失效的key
|
||||
String expiredKey = message.toString();
|
||||
String KEEPLIVEKEY_PREFIX = VideoManagerConstants.MEDIA_SERVER_KEEPALIVE_PREFIX + userSetting.getServerId() + "_";
|
||||
if(!expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){
|
||||
return;
|
||||
}
|
||||
|
||||
String mediaServerId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
|
||||
logger.info("[zlm心跳到期]:" + mediaServerId);
|
||||
// 发起http请求验证zlm是否确实无法连接,如果确实无法连接则发送离线事件,否则不作处理
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
JSONObject mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
if (mediaServerConfig != null && mediaServerConfig.getInteger("code") == 0) {
|
||||
logger.info("[zlm心跳到期]:{}验证后zlm仍在线,恢复心跳信息", mediaServerId);
|
||||
// 添加zlm信息
|
||||
mediaServerService.updateMediaServerKeepalive(mediaServerId, mediaServerConfig);
|
||||
}else {
|
||||
publisher.zlmOfflineEventPublish(mediaServerId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -19,7 +20,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
@ -39,7 +39,6 @@ import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
|||
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
@ -53,6 +52,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class);
|
||||
|
||||
private final String zlmKeepaliveKeyPrefix = "zlm-keepalive_";
|
||||
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
|
||||
|
@ -83,10 +84,12 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
@Autowired
|
||||
private ZLMRTPServerFactory zlmrtpServerFactory;
|
||||
|
||||
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
|
@ -130,7 +133,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
logger.info("media server [ {} ] ssrcConfig is null", mediaServerItem.getId());
|
||||
return null;
|
||||
}else {
|
||||
String ssrc = null;
|
||||
String ssrc;
|
||||
if (presetSsrc != null) {
|
||||
ssrc = presetSsrc;
|
||||
}else {
|
||||
|
@ -398,15 +401,43 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
if (serverItem.isAutoConfig()) {
|
||||
setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
|
||||
}
|
||||
final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId();
|
||||
dynamicTask.stop(zlmKeepaliveKey);
|
||||
dynamicTask.startDelay(zlmKeepaliveKey, new KeepAliveTimeoutRunnable(serverItem), (serverItem.getHookAliveInterval() + 5) * 1000);
|
||||
publisher.zlmOnlineEventPublish(serverItem.getId());
|
||||
logger.info("[ZLM] 连接成功 {} - {}:{} ",
|
||||
zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort());
|
||||
}
|
||||
|
||||
class KeepAliveTimeoutRunnable implements Runnable{
|
||||
|
||||
private MediaServerItem serverItem;
|
||||
|
||||
public KeepAliveTimeoutRunnable(MediaServerItem serverItem) {
|
||||
this.serverItem = serverItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("[zlm心跳到期]:" + serverItem.getId());
|
||||
// 发起http请求验证zlm是否确实无法连接,如果确实无法连接则发送离线事件,否则不作处理
|
||||
JSONObject mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(serverItem);
|
||||
if (mediaServerConfig != null && mediaServerConfig.getInteger("code") == 0) {
|
||||
logger.info("[zlm心跳到期]:{}验证后zlm仍在线,恢复心跳信息,请检查zlm是否可以正常向wvp发送心跳", serverItem.getId());
|
||||
// 添加zlm信息
|
||||
updateMediaServerKeepalive(serverItem.getId(), mediaServerConfig);
|
||||
}else {
|
||||
publisher.zlmOfflineEventPublish(serverItem.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void zlmServerOffline(String mediaServerId) {
|
||||
delete(mediaServerId);
|
||||
final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + mediaServerId;
|
||||
dynamicTask.stop(zlmKeepaliveKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -429,7 +460,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
}else {
|
||||
clearRTPServer(serverItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -465,7 +495,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
}
|
||||
|
||||
// 获取分数最低的,及并发最低的
|
||||
Set<Object> objects = RedisUtil.ZRange(key, 0, -1);
|
||||
Set<Object> objects = RedisUtil.zRange(key, 0, -1);
|
||||
ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects);
|
||||
|
||||
String mediaServerId = (String)mediaServerObjectS.get(0);
|
||||
|
@ -625,9 +655,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
|||
return;
|
||||
}
|
||||
}
|
||||
String key = VideoManagerConstants.MEDIA_SERVER_KEEPALIVE_PREFIX + userSetting.getServerId() + "_" + mediaServerId;
|
||||
int hookAliveInterval = mediaServerItem.getHookAliveInterval() + 2;
|
||||
RedisUtil.set(key, data, hookAliveInterval);
|
||||
final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + mediaServerItem.getId();
|
||||
dynamicTask.stop(zlmKeepaliveKey);
|
||||
dynamicTask.startDelay(zlmKeepaliveKey, new KeepAliveTimeoutRunnable(mediaServerItem), (mediaServerItem.getHookAliveInterval() + 5) * 1000);
|
||||
}
|
||||
|
||||
private MediaServerItem getOneFromDatabase(String mediaServerId) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
|
|
@ -33,11 +33,11 @@ public class SpringBeanFactory implements ApplicationContextAware {
|
|||
/**
|
||||
* 获取对象 这里重写了bean方法,起主要作用
|
||||
*/
|
||||
public static Object getBean(String beanId) throws BeansException {
|
||||
public static <T> T getBean(String beanId) throws BeansException {
|
||||
if (applicationContext == null) {
|
||||
return null;
|
||||
}
|
||||
return applicationContext.getBean(beanId);
|
||||
return (T) applicationContext.getBean(beanId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,15 +5,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @description:Redis工具类
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月6日 下午8:27:29
|
||||
* Redis工具类
|
||||
* @author swwheihei
|
||||
* @date 2020年5月6日 下午8:27:29
|
||||
*/
|
||||
@SuppressWarnings(value = {"rawtypes", "unchecked"})
|
||||
public class RedisUtil {
|
||||
|
@ -21,9 +19,9 @@ public class RedisUtil {
|
|||
private static RedisTemplate redisTemplate;
|
||||
|
||||
static {
|
||||
redisTemplate = (RedisTemplate)SpringBeanFactory.getBean("redisTemplate");
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
* @param key 键
|
||||
|
@ -31,6 +29,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean expire(String key, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||
|
@ -45,9 +46,11 @@ public class RedisUtil {
|
|||
/**
|
||||
* 根据 key 获取过期时间
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public static long getExpire(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@ -57,6 +60,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hasKey(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.hasKey(key);
|
||||
} catch (Exception e) {
|
||||
|
@ -71,6 +77,9 @@ public class RedisUtil {
|
|||
* @param key 键(一个或者多个)
|
||||
*/
|
||||
public static boolean del(String... key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
if (key != null && key.length > 0) {
|
||||
if (key.length == 1) {
|
||||
|
@ -95,6 +104,9 @@ public class RedisUtil {
|
|||
* @return 值
|
||||
*/
|
||||
public static Object get(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return key == null ? null : redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
|
@ -105,6 +117,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean set(String key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
return true;
|
||||
|
@ -122,6 +137,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean set(String key, Object value, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
|
@ -142,6 +160,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static long incr(String key, long delta) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递增因子必须大于 0");
|
||||
}
|
||||
|
@ -155,6 +176,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static long decr(String key, long delta) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递减因子必须大于 0");
|
||||
}
|
||||
|
@ -170,6 +194,9 @@ public class RedisUtil {
|
|||
* @return 值
|
||||
*/
|
||||
public static Object hget(String key, String item) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForHash().get(key, item);
|
||||
}
|
||||
|
||||
|
@ -179,6 +206,9 @@ public class RedisUtil {
|
|||
* @return 对应的多个键值
|
||||
*/
|
||||
public static Map<Object, Object> hmget(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
|
@ -189,6 +219,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hmset(String key, Map<Object, Object> map) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
return true;
|
||||
|
@ -206,6 +239,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hmset(String key, Map<Object, Object> map, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
if (time > 0) {
|
||||
|
@ -226,6 +262,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hset(String key, String item, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
return true;
|
||||
|
@ -244,6 +283,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hset(String key, String item, Object value, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
if (time > 0) {
|
||||
|
@ -262,6 +304,9 @@ public class RedisUtil {
|
|||
* @param item 项(可以多个,no null)
|
||||
*/
|
||||
public static void hdel(String key, Object... item) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
redisTemplate.opsForHash().delete(key, item);
|
||||
}
|
||||
|
||||
|
@ -272,6 +317,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean hHasKey(String key, String item) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForHash().hasKey(key, item);
|
||||
}
|
||||
|
||||
|
@ -283,6 +331,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Double hincr(String key, String item, Double by) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForHash().increment(key, item, by);
|
||||
}
|
||||
|
||||
|
@ -294,6 +345,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Double hdecr(String key, String item, Double by) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForHash().increment(key, item, -by);
|
||||
}
|
||||
|
||||
|
@ -305,6 +359,9 @@ public class RedisUtil {
|
|||
* @return 值
|
||||
*/
|
||||
public static Set<Object> sGet(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
|
@ -320,6 +377,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean sHasKey(String key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForSet().isMember(key, value);
|
||||
} catch (Exception e) {
|
||||
|
@ -335,6 +395,9 @@ public class RedisUtil {
|
|||
* @return 成功个数
|
||||
*/
|
||||
public static long sSet(String key, Object... values) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
} catch (Exception e) {
|
||||
|
@ -351,6 +414,9 @@ public class RedisUtil {
|
|||
* @return 成功放入个数
|
||||
*/
|
||||
public static long sSet(String key, long time, Object... values) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
long count = redisTemplate.opsForSet().add(key, values);
|
||||
if (time > 0) {
|
||||
|
@ -369,6 +435,9 @@ public class RedisUtil {
|
|||
* @return 长度
|
||||
*/
|
||||
public static long sGetSetSize(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
} catch (Exception e) {
|
||||
|
@ -384,6 +453,9 @@ public class RedisUtil {
|
|||
* @return 成功移除个数
|
||||
*/
|
||||
public static long setRemove(String key, Object... values) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForSet().remove(key, values);
|
||||
} catch (Exception e) {
|
||||
|
@ -401,6 +473,9 @@ public class RedisUtil {
|
|||
* @param score
|
||||
*/
|
||||
public static void zAdd(Object key, Object value, double score) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
redisTemplate.opsForZSet().add(key, value, score);
|
||||
}
|
||||
|
||||
|
@ -411,6 +486,9 @@ public class RedisUtil {
|
|||
* @param value
|
||||
*/
|
||||
public static void zRemove(Object key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
redisTemplate.opsForZSet().remove(key, value);
|
||||
}
|
||||
|
||||
|
@ -422,6 +500,9 @@ public class RedisUtil {
|
|||
* @param delta -1 表示减 1 表示加1
|
||||
*/
|
||||
public static Double zIncrScore(Object key, Object value, double delta) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().incrementScore(key, value, delta);
|
||||
}
|
||||
|
||||
|
@ -433,6 +514,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Double zScore(Object key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().score(key, value);
|
||||
}
|
||||
|
||||
|
@ -444,6 +528,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Long zRank(Object key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().rank(key, value);
|
||||
}
|
||||
|
||||
|
@ -454,6 +541,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Long zSize(Object key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().zCard(key);
|
||||
}
|
||||
|
||||
|
@ -467,7 +557,10 @@ public class RedisUtil {
|
|||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static Set<Object> ZRange(Object key, int start, int end) {
|
||||
public static Set<Object> zRange(Object key, int start, int end) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().range(key, start, end);
|
||||
}
|
||||
/**
|
||||
|
@ -479,6 +572,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(Object key, int start, int end) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
|
||||
}
|
||||
/**
|
||||
|
@ -492,6 +588,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Set<String> zRevRange(Object key, int start, int end) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().reverseRange(key, start, end);
|
||||
}
|
||||
/**
|
||||
|
@ -503,6 +602,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Set<String> zSortRange(Object key, int min, int max) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForZSet().rangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
|
@ -517,6 +619,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static List<Object> lGet(String key, long start, long end) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
} catch (Exception e) {
|
||||
|
@ -531,6 +636,9 @@ public class RedisUtil {
|
|||
* @return 长度
|
||||
*/
|
||||
public static long lGetListSize(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForList().size(key);
|
||||
} catch (Exception e) {
|
||||
|
@ -548,6 +656,9 @@ public class RedisUtil {
|
|||
* @return 值
|
||||
*/
|
||||
public static Object lGetIndex(String key, long index) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
} catch (Exception e) {
|
||||
|
@ -563,6 +674,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean lSet(String key, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
return true;
|
||||
|
@ -580,6 +694,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean lSet(String key, Object value, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
if (time > 0) {
|
||||
|
@ -599,6 +716,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean lSetList(String key, List<Object> values) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, values);
|
||||
return true;
|
||||
|
@ -616,6 +736,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean lSetList(String key, List<Object> values, long time) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, values);
|
||||
if (time > 0) {
|
||||
|
@ -636,6 +759,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static boolean lUpdateIndex(String key, long index, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForList().set(key, index, value);
|
||||
return true;
|
||||
|
@ -655,6 +781,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static long lRemove(String key, long count, Object value) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForList().remove(key, count, value);
|
||||
} catch (Exception e) {
|
||||
|
@ -669,6 +798,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Object lLeftPop(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForList().leftPop(key);
|
||||
}
|
||||
|
||||
|
@ -678,6 +810,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Object lrightPop(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
return redisTemplate.opsForList().rightPop(key);
|
||||
}
|
||||
|
||||
|
@ -687,6 +822,9 @@ public class RedisUtil {
|
|||
* @return true / false
|
||||
*/
|
||||
public static List<Object> keys(String key) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
try {
|
||||
Set<String> set = redisTemplate.keys(key);
|
||||
return new ArrayList<>(set);
|
||||
|
@ -727,6 +865,9 @@ public class RedisUtil {
|
|||
* @return
|
||||
*/
|
||||
public static List<Object> scan(String query) {
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
Set<String> resultKeys = (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
|
||||
ScanOptions scanOptions = ScanOptions.scanOptions().match("*" + query + "*").count(1000).build();
|
||||
Cursor<byte[]> scan = connection.scan(scanOptions);
|
||||
|
@ -743,9 +884,10 @@ public class RedisUtil {
|
|||
|
||||
// ============================== 消息发送与订阅 ==============================
|
||||
public static void convertAndSend(String channel, JSONObject msg) {
|
||||
// redisTemplate.convertAndSend(channel, msg);
|
||||
if (redisTemplate == null) {
|
||||
redisTemplate = SpringBeanFactory.getBean("redisTemplate");
|
||||
}
|
||||
redisTemplate.convertAndSend(channel, msg);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -179,7 +179,8 @@ public class PlatformController {
|
|||
commanderForPlatform.register(parentPlatform, null, null);
|
||||
}
|
||||
|
||||
} else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 关闭启用时注销
|
||||
} else if (parentPlatformOld != null && parentPlatformOld.isEnable()) {
|
||||
// 关闭启用时注销
|
||||
commanderForPlatform.unregister(parentPlatform, null, null);
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue