redis Could not get a resource from the pool

滑山论贱 发布于 2014/11/19 14:13
阅读 19K+
收藏 0

public static void main(String[] args){
  for(int i=0;i<10;i++){
   RedisDBUtil test=new RedisDBUtil("127.0.0.1",6397,0);//构造方法在下面
   System.out.println("i="+i+"");
   test.setValue("123456789","123456789");
   test.close();
  }
 }

 

/**
  * 构造函数, 适用于无密码认证的Redis服务器
  * @param ip Redis服务器IP地址
  * @param port Redis服务器端口
  * @param bucket 数据存放地点(范围0至15)
  */
 public RedisDBUtil(String ip, int port, int bucket) {
  if (null == jedisPool) {
   this.bucket = bucket;
   jedisPool = new JedisPool(config, ip, port);
   logger.info("创建JedisPool成功.");
  }
 }

2014-11-19 14:10:37,891 INFO  -创建JedisPool成功.
i=0
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
 at redis.clients.util.Pool.getResource(Pool.java:42)
 at redis.clients.jedis.JedisPool.getResource(JedisPool.java:84)
 at com.count.util.RedisDBUtil.getJedisFormPool(RedisDBUtil.java:197)
 at com.count.util.RedisDBUtil.setValue(RedisDBUtil.java:127)
 at com.count.util.Test.main(Test.java:8)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
 at redis.clients.jedis.Connection.connect(Connection.java:150)
 at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:71)
 at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1783)
 at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:65)
 at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:836)
 at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:434)
 at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
 at redis.clients.util.Pool.getResource(Pool.java:40)
 ... 4 more

这个redis连接池为什么只能连接一次,难道还要在redis service设置什么东西?

求大神解答

 

加载中
0
滑山论贱
滑山论贱

JedisPoolConfig 设置如下

private static JedisPoolConfig config;//Jedis客户端池配置
 static{
        config =new JedisPoolConfig();
        config.setMaxTotal(60000);//设置最大连接数 
        config.setMaxIdle(1000); //设置最大空闲数
        config.setMaxWaitMillis(3000);//设置超时时间 
        config.setTestOnBorrow(true);
 }

0
滑山论贱
滑山论贱
我擦,端口错误了。。。。
返回顶部
顶部