在使用JedisPool连接Redis的时候出现以下异常:
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:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at jedis.JedisPoolDemo$.getConnection(JedisPoolDemo.scala:19)
at jedis.JedisPoolDemo$.main(JedisPoolDemo.scala:24)
at jedis.JedisPoolDemo.main(JedisPoolDemo.scala)
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)
异常中说的很清楚:无法从池中获取资源
说明是参数的错误,IP地址或者是端口号,密码
再如果修改以后还报以下错误:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException:
java.net.ConnectException: Connection refused: connectat
redis.clients.jedis.Connection.connect(Connection.java:154)at
redis.clients.jedis.BinaryClient.connect(BinaryClient.java:83)at
redis.clients.jedis.Connection.sendCommand(Connection.java:93)at
redis.clients.jedis.BinaryClient.set(BinaryClient.java:100)at
redis.clients.jedis.Client.set(Client.java:29)at redis.clients.jedis.Jedis.set(Jedis.java:65)at
cn.guyouda.redis.Test1.main(Test1.java:14```
**异常中的信息是拒绝了连接,**说明不是参数的问题,而是redis配置文件的问题
解决方法:
修改redis.conf
1.注释掉 bind 127.0.0.1
2.关闭安全模式: protected-mode no
再关闭redis服务,重新跑一下就发现问题解决了。