...
|
...
|
@@ -16,11 +16,15 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* Created by craig.qin on 2017/7/11.
|
...
|
...
|
@@ -29,12 +33,16 @@ import java.util.Map; |
|
|
public class RedisOperateServiceImpl implements RedisOperateService {
|
|
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
public static final int TIMEOUT = 2000;
|
|
|
|
|
|
@Autowired
|
|
|
MTypeInfoMapper mTypeInfoMapper;
|
|
|
|
|
|
@Autowired
|
|
|
IMObjectInfoService mobjectService;
|
|
|
|
|
|
Map<String, JedisPool> JEDIS_POOL_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 从cmdb:监控对象中取host数据
|
...
|
...
|
@@ -334,7 +342,7 @@ public class RedisOperateServiceImpl implements RedisOperateService { |
|
|
if(sb.length()>0){
|
|
|
sb.append("<br/>");
|
|
|
}
|
|
|
sb.append("total delete "+RedisCommonUtil.removeRedisKeyByPrefix(ip,port,prefix)+" keys with prefix "+prefix+" at "+ipAndPortStr);
|
|
|
sb.append("total delete "+RedisCommonUtil.removeRedisKeyByPrefix(fecthJedis(ip,port),prefix)+" keys with prefix "+prefix+" at "+ipAndPortStr);
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -343,4 +351,25 @@ public class RedisOperateServiceImpl implements RedisOperateService { |
|
|
rtnBaseResponse.setData(sb.toString());
|
|
|
return rtnBaseResponse;
|
|
|
}
|
|
|
|
|
|
private Jedis fecthJedis(String ip, int port) {
|
|
|
String jedisUrl=ip+":"+port;
|
|
|
JedisPool jedisPool = JEDIS_POOL_MAP.get(jedisUrl);
|
|
|
|
|
|
if (null == jedisPool) {
|
|
|
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
|
|
jedisPoolConfig.setMaxIdle(8);
|
|
|
jedisPoolConfig.setMaxTotal(8);
|
|
|
jedisPool = new JedisPool(jedisPoolConfig, ip, port, TIMEOUT);
|
|
|
JEDIS_POOL_MAP.put(jedisUrl, jedisPool);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
return jedisPool.getResource();
|
|
|
} catch (Exception e) {
|
|
|
logger.error("RedisOperateServiceImpl fecth Jedis client {} , error {}",jedisUrl, e);
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|