diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/com/xhpc/common/redis/service/RedisService.java b/ruoyi-common/ruoyi-common-redis/src/main/java/com/xhpc/common/redis/service/RedisService.java index ef9e689c..6b713228 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/com/xhpc/common/redis/service/RedisService.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/com/xhpc/common/redis/service/RedisService.java @@ -1,11 +1,5 @@ package com.xhpc.common.redis.service; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.HashOperations; @@ -13,6 +7,9 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Component; +import java.util.*; +import java.util.concurrent.TimeUnit; + /** * spring redis 工具类 * @@ -102,20 +99,29 @@ public class RedisService * @param collection 多个对象 * @return */ - public long deleteObject(final Collection collection) - { + public long deleteObject(final Collection collection) { + return redisTemplate.delete(collection); } + /** + * 删除单个key下的某个值 + * + * @param key + */ + public void deleteSetVal(final String key, final Object val) { + + redisTemplate.opsForSet().remove(key, val); + } + /** * 缓存List数据 * - * @param key 缓存的键值 + * @param key 缓存的键值 * @param dataList 待缓存的List数据 * @return 缓存的对象 */ - public long setCacheList(final String key, final List dataList) - { + public long setCacheList(final String key, final List dataList) { Long count = redisTemplate.opsForList().rightPushAll(key, dataList); return count == null ? 0 : count; } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java index bee36709..7cefce17 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java @@ -1,7 +1,6 @@ package com.xhpc.pp.logic; import com.xhpc.common.dto.ConnectorStatusInfo; -import com.xhpc.pp.config.EarlierBeanConf; import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.logic.ServiceLogic; @@ -12,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import java.util.Collection; import java.util.Map; import java.util.Set; @@ -39,10 +39,10 @@ public class RegisterLogic implements ServiceLogic { log.info("pile not in whitelist ({}) ", pileNo); hexCode = ServiceResult.HEX_01; resultCode = ServiceResult.FAIL; - } else if (!EarlierBeanConf.ifcanreg(pileNo)) { - log.info("pile already registered ({}) ", pileNo); - hexCode = ServiceResult.HEX_01; - resultCode = ServiceResult.FAIL; +// } else if (!EarlierBeanConf.ifcanreg(pileNo)) { // not a stable reliable method +// log.info("pile already registered ({}) ", pileNo); +// hexCode = ServiceResult.HEX_01; +// resultCode = ServiceResult.FAIL; } else { String pkey = "pile:".concat(pileNo); Map cachePile = REDIS.getCacheMap(pkey); @@ -60,7 +60,14 @@ public class RegisterLogic implements ServiceLogic { cacheGun.put("statusInt", ConnectorStatusInfo.OFF_LINE); cacheGun.put("svcSrv", localIPAndPort); REDIS.setCacheMap(gunkey, cacheGun); - cachePileGunSvcSrv(gunkey); + String svcSrvKeyNew = "svcSrvGuns:".concat(getLocalIPAndPort()); + cachePileGunSvcSrv(gunkey, svcSrvKeyNew); + final Collection cacheSvcSrvKeys = REDIS.keys("svcSrvGuns:*"); + for (String svcSrvKey : cacheSvcSrvKeys) { + if (!svcSrvKey.equals(svcSrvKeyNew)) { + REDIS.deleteSetVal(svcSrvKey, gunkey); + } + } } log.info("pile (re)registered ({}) ", pileNo); } @@ -71,12 +78,11 @@ public class RegisterLogic implements ServiceLogic { return new ServiceResult(HexUtils.toBytes(resultStr), resultCode); } - private void cachePileGunSvcSrv(String gunkey) { + private void cachePileGunSvcSrv(String gunkey, String svcSrvKey) { - String svcKey = "svcSrvGuns:".concat(getLocalIPAndPort()); - Set svcPileGuns = REDIS.getCacheSet(svcKey); + Set svcPileGuns = REDIS.getCacheSet(svcSrvKey); svcPileGuns.add(gunkey); - REDIS.setCacheSet(svcKey, svcPileGuns); + REDIS.setCacheSet(svcSrvKey, svcPileGuns); } } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/HBCheckTask.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/HBCheckTask.java index 4f2bd754..e54ef621 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/HBCheckTask.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/HBCheckTask.java @@ -18,7 +18,6 @@ public class HBCheckTask { @Scheduled(fixedRate = 10000) protected void run() { - System.out.println("hbchk.."); String svcSrvKey = "svcSrvGuns".concat(getLocalIPAndPort()); List cacheGunkeyList = REDIS.getCacheList(svcSrvKey); Long now = Calendar.getInstance().getTimeInMillis();