redis集群使用jedis进行连接时只能对name进行取值和设值,其他任何key都报connect timed out
@Test
public void testJedis3() throws IOException {
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
JedisCluster jedisCluster = new JedisCluster(nodes);
jedisCluster.set("name", "1234");
System.out.println(jedisCluster.get("name"));
jedisCluster.close();
}[/code]
成功取值 1234
@Test
public void testJedis3() throws IOException {
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
nodes.add(new HostAndPort(ip, host));
JedisCluster jedisCluster = new JedisCluster(nodes);
jedisCluster.set("ggg", "1234");
System.out.println(jedisCluster.get("ggg"));
jedisCluster.close();
}[/code]
报错
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 redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:31)
at redis.clients.jedis.JedisCluster.set(JedisCluster.java:103)
at top.catotaku.common.test.JedisTest.testJedis3(JedisTest.java:52)
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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
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)
... 40 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:184)
... 47 more相关推荐
Redis使用lettuce和jedis
Redis使用lettuce和jedis
Spring Boot 3.X Redis连接问题排查与优化
Redis作为高性能的内存数据库,在现代分布式系统中扮演着重要角色。其基于内存的键值存储机制和丰富的数据结构支持,使其成为缓存、会话管理等场景的首选方案。在Spring Boot应用中,通过Lettuce或Jedis客户端与Redis交互时,连接管理是关键环节。合理的连接池配置能显著提升性能,而错误的配置则可能导致连接泄漏或超时问题。本文针对Spring Boot 3.X升级过程中遇到的典型Redis连接问题,从网络连通性、认证配置、SSL/TLS设置等维度,详细解析了排查思路和解决方案,并提供了生产环境下
真实工程中的非典型学习:从故障断点反向构建技术能力
在现代软件工程中,‘学习’早已脱离教科书式的线性路径,演变为以业务故障为起点、多维度交织的网状认知重构过程。其核心原理在于:知识不是按学科分层积累,而是在真实系统压力下,围绕具体问题(如超时异常、连接池耗尽)逆向拼合协议层、数据层、架构层等技术子集。这种‘断点回溯’式实践,显著提升问题定位效率与技术决策准确性,支撑高并发、强一致、可观测等关键场景落地。尤其适用于自学者突破‘学而不用’瓶颈、新工程师接手遗留系统、技术负责人验证架构选型——当SocketTimeoutException和Redis连接池耗尽成为
java连接Redis所需jar包
Redis:java连接Redis所需的jar包,包括jedis.jar和common-pool.jar!
详解Redis开启远程登录连接
今天使用jedis客户端api连接远程连接redis的时候,一直报错,如下: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect at redis.clients.jedis.Connection.connect(Connection.java:164) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80) at redis.clie


Web 开发
