使用JedisPool连接Redis报错( Could not get a resource from the pool和 Connection refused)

在使用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服务,重新跑一下就发现问题解决了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值