JedisCluster 运行报错,求大神帮忙啊

hanger_liu 2016-09-23 11:20:13
搭建了一个集群环境,用jedisCluster去操作,没有keys命令,就按照网上的写法,写了一个方法出来。但是,for循环后发现会报如下错误,不知道怎么解决,大神帮忙

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at CloudPanSys.Cache.Redis.config.Test.main(Test.java:91)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 2 more

代码如下:
public class Test {
public static Map<String, JedisPool> ConAllNodes(){
HashSet<HostAndPort> nodes = new HashSet<HostAndPort>();
//创建多个主机和端口实例
HostAndPort hostAndPort = new HostAndPort("172.168.82.230", 7000);
HostAndPort hostAndPort1 = new HostAndPort("172.168.82.230", 7001);
HostAndPort hostAndPort2 = new HostAndPort("172.168.82.230", 7002);
HostAndPort hostAndPort3 = new HostAndPort("172.168.82.228", 7003);
HostAndPort hostAndPort4 = new HostAndPort("172.168.82.228", 7004);
HostAndPort hostAndPort5 = new HostAndPort("172.168.82.228", 7005);

//添加多个主机和端口到集合中
nodes.add(hostAndPort);
nodes.add(hostAndPort1);
nodes.add(hostAndPort2);
nodes.add(hostAndPort3);
nodes.add(hostAndPort4);
nodes.add(hostAndPort5);

JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(10000);
config.setMaxIdle(500);
config.setMinIdle(50);
config.setMaxWaitMillis(10000);
config.setTestOnReturn(true);
config.setTestWhileIdle(true);
config.setTestOnBorrow(true);
config.setTimeBetweenEvictionRunsMillis(30000);
config.setNumTestsPerEvictionRun(10);
config.setMinEvictableIdleTimeMillis(60000);
JedisCluster j = new JedisCluster(nodes,5000,5000,config);
Map<String, JedisPool> clusterNodes = j.getClusterNodes();
return clusterNodes;
}
public static void main(String args[]) throws IOException, InterruptedException{
for(int i=0;i<500;i++){
TreeSet<String> keys = new TreeSet<>();
Map<String, JedisPool> clusterNodes = ConAllNodes();
JedisPool jp = null;
Jedis connection=null;
for(String k : clusterNodes.keySet()){
jp = clusterNodes.get(k);
try{
System.out.println(k);
System.out.println(jp.getNumActive());
connection=jp.getResource();
keys.addAll( connection.keys("*"));
}catch (Exception e){
e.printStackTrace();
}finally{
if(connection!=null){
connection.close();
}
}

}

for(String x:keys){
System.out.println(x);
}

}
}
}

...全文
281 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanger_liu 2016-09-23
  • 打赏
  • 举报
回复
没有人吗 ?急求解决方法啊

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧