博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis ConnectionException
阅读量:5124 次
发布时间:2019-06-13

本文共 4218 字,大约阅读时间需要 14 分钟。

JAVA 远程链接Redis服务失败,错误信息如下:

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

at redis.clients.util.Pool.getResource(Pool.java:50)

at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99)
at cn.crxy.offline6.javase.day20161115.RedisTemplateTest.jedisPool(RedisTemplateTest.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:164)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:82)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1641)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:85)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861)
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:48)
... 29 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:158)
... 36 more

问题排查步骤如下:

1、保证 java程序端与 redis服务端相互ping 通

a) 本地 DOS 去 ping远程服务器IP

b) 远程服务器ping 本地IP

2、修改Redis服务器配置文件 (我这里是 make install 安装)

vi /etc/redis.conf

其中有两处 bing 127.0.0.1 全部用“#”注释掉

3、重启Redis-server

先查看当前Redis 进程

退出redis-cli,也可以kill redis-cli 进程

停止服务:redis-server shutdown 或 redis-cli shutdown

开启服务:redis-server /etc/redis.conf

4、测试

可以先在本地DOS下进行连接访问,首先要进入本地Redis安装目录下

 如果测试通过,就可以进行java程序连接了

 

转载于:https://www.cnblogs.com/louxindong/p/6129266.html

你可能感兴趣的文章
18.QT-QPlainEdit 信号与槽
查看>>
Linux-使用之vim出现的问题
查看>>
资料收藏夹
查看>>
bzoj4380[POI2015]Myjnie dp
查看>>
jquery动画 -- 1.加载指示器
查看>>
基础C#总结
查看>>
CSS基础选择器(选择器的优先级),CSS样式块( 长度/颜色/显示方式/文本样式),盒模型组成,盒模型-block,盒模型布局...
查看>>
strcpy、memcpy和memset的区别
查看>>
AI单挑Dota 2世界冠军:被电脑虐哭……
查看>>
Python3 循环
查看>>
动画---图形图像与动画(三)Animation效果的XML实现
查看>>
题解 P5301 【[GXOI/GZOI2019]宝牌一大堆】
查看>>
Longest Valid Parentheses
查看>>
Android 中的 Service 全面总结
查看>>
delphi下实现ribbon界面的方法(一)
查看>>
Windows 8操作技巧之快捷键大全
查看>>
Linux命令
查看>>
Spring-Boot——Cache
查看>>
WPF vs2015,vs2012 添加ArcObjects SDK
查看>>
dba_segments和dba_tables的不同
查看>>