我是靠谱客的博主 呆萌钻石,最近开发中收集的这篇文章主要介绍报错:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

使用spring测试redis相关操作时,出现以下错误

"C:Z capjdk8u91binjava.exe" "-javaagent:C:Z capideaIntelliJ IDEA 2020.2.3libidea_rt.jar=60156:C:Z capideaIntelliJ IDEA 2020.2.3bin" -Dfile.encoding=UTF-8 -classpath "C:Z capjdk8u91jrelibcharsets.jar;C:Z capjdk8u91jrelibdeploy.jar;C:Z capjdk8u91jrelibextaccess-bridge-64.jar;C:Z capjdk8u91jrelibextcldrdata.jar;C:Z capjdk8u91jrelibextdnsns.jar;C:Z capjdk8u91jrelibextjaccess.jar;C:Z capjdk8u91jrelibextjfxrt.jar;C:Z capjdk8u91jrelibextlocaledata.jar;C:Z capjdk8u91jrelibextnashorn.jar;C:Z capjdk8u91jrelibextsunec.jar;C:Z capjdk8u91jrelibextsunjce_provider.jar;C:Z capjdk8u91jrelibextsunmscapi.jar;C:Z capjdk8u91jrelibextsunpkcs11.jar;C:Z capjdk8u91jrelibextzipfs.jar;C:Z capjdk8u91jrelibjavaws.jar;C:Z capjdk8u91jrelibjce.jar;C:Z capjdk8u91jrelibjfr.jar;C:Z capjdk8u91jrelibjfxswt.jar;C:Z capjdk8u91jrelibjsse.jar;C:Z capjdk8u91jrelibmanagement-agent.jar;C:Z capjdk8u91jrelibplugin.jar;C:Z capjdk8u91jrelibresources.jar;C:Z capjdk8u91jrelibrt.jar;F:java相关文件RedisFolderRedis-Stringtargetclasses;C:Users鲍超.m2repositoryredisclientsjedis3.3.0jedis-3.3.0.jar;C:Users鲍超.m2repositoryorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;C:Users鲍超.m2repositoryorgapachecommonscommons-pool22.6.2commons-pool2-2.6.2.jar;C:Users鲍超.m2repositoryorgspringframeworkdataspring-data-redis2.3.3.RELEASEspring-data-redis-2.3.3.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkdataspring-data-keyvalue2.3.3.RELEASEspring-data-keyvalue-2.3.3.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkdataspring-data-commons2.3.3.RELEASEspring-data-commons-2.3.3.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-context5.2.8.RELEASEspring-context-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-expression5.2.8.RELEASEspring-expression-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-tx5.2.8.RELEASEspring-tx-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-beans5.2.8.RELEASEspring-beans-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-core5.2.8.RELEASEspring-core-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-jcl5.2.8.RELEASEspring-jcl-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-oxm5.2.8.RELEASEspring-oxm-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-aop5.2.8.RELEASEspring-aop-5.2.8.RELEASE.jar;C:Users鲍超.m2repositoryorgspringframeworkspring-context-support5.2.8.RELEASEspring-context-support-5.2.8.RELEASE.jar" com.bc.string.StringTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:282)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:476)
	at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:134)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:97)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:84)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:215)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
	at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
	at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
	at com.bc.string.StringTest.main(StringTest.java:14)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at redis.clients.jedis.util.Pool.getResource(Pool.java:59)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:288)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:15)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:272)
	... 9 more
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to 192.168.83.128:6379
	at redis.clients.jedis.Connection.connect(Connection.java:165)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:109)
	at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1904)
	at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:130)
	at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:889)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:424)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:349)
	at redis.clients.jedis.util.Pool.getResource(Pool.java:50)
	... 12 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.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:53)
	at redis.clients.jedis.Connection.connect(Connection.java:158)
	... 19 more

Process finished with exit code 1

解决方法:
使用的redis是在linux中,而linux中防火墙未关闭,导致redis无法访问,关闭linux的防火墙即可,在linux中操作以下指令:

systemctl stop firewalld

查看防火墙状态指令:

systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2020-11-18 14:26:15 CST; 9s ago
     Docs: man:firewalld(1)
  Process: 6255 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 6255 (code=exited, status=0/SUCCESS)

Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:22:42 localhost.localdomain firewalld[6255]: WARNING: COMMAND_FAILED: '/u....
Nov 18 14:26:14 localhost.localdomain systemd[1]: Stopping firewalld - dynamic fire....
Nov 18 14:26:15 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firew....
Hint: Some lines were ellipsized, use -l to show in full.

防火墙已关闭,即可在spring中访问redis了

最后

以上就是呆萌钻石为你收集整理的报错:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.的全部内容,希望文章能够帮你解决报错:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部