gpt4 book ai didi

java - JedisCluster 在 2.7.x 中工作,但在 Jedis 2.9.x 中不工作,JedisConnectionException 和 Connection refused

转载 作者:IT王子 更新时间:2023-10-29 06:06:09 24 4
gpt4 key购买 nike

我的代码在 Jedis 2.7.x 中已经有几个月了。但我发现我有同样的问题 https://github.com/xetorthio/jedis/issues/1625 (Redis 服务器重启时 JedisPool.getResource block )。所以我从 2.7.x 切换到 2.9.x。我正在使用相同的代码来创建 JedisCluster。但是它无法连接并从 Jedis 获取数据。

我创建了一个单例 JedisCluster 实例,每次我只使用 JedisCluster.get() 来获取数据。我不关闭集群的连接。

更多信息:我的redis是3.2.8。我将一台主机用作 JedisCluster,并且没有从机。我想使用 JedisCluster 模式而不是 Jedis 模式的原因是我有另一个系统需要调用具有多主机的 JedisCluster。我想先在当前单机集群中测试代码,然后再部署代码到那个系统

cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:1
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0

相同的代码在 2.7.x 中有效,但在 2.9.x 中无效。

@Singleton
JedisCluster jedisCluster(){
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("10.xx.xx.xx", 6379));
GenericObjectPoolConfig jedisPoolConfig = new GenericObjectPoolConfig();
jedisPoolConfig.setMaxTotal(16);
jedisPoolConfig.setMaxIdle(16);
return new JedisCluster(jedisClusterNodes, 2000, 1000, 5, jedisPoolConfig);
}
//When using cluster
jedisCluster.set("foo", "bar");
String value = jedisCluster.get("foo");

以下代码适用于 2.9.x

Jedis jedis = new Jedis("xx.xx.xxx.xx",6379);
System.out.println(jedis.get("foo"));

我 ssh 到我的 Redis 主机并运行 cli

127.0.0.1:6379> get foo
"bar

我得到的异常

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:31) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisCluster.get(JedisCluster.java:124) ~[jedis-2.9.x.jar:?]
.........
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
at redis.clients.jedis.Connection.connect(Connection.java:207) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106) ~[jedis-2.9.x.jar:?]
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:836) ~[commons-pool2-2.2.jar:2.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:434) ~[commons-pool2-2.2.jar:2.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361) ~[commons-pool2-2.2.jar:2.2]
at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.x.jar:?]
... 45 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_144]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_144]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_144]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_144]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_144]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_144]
at redis.clients.jedis.Connection.connect(Connection.java:184) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767) ~[jedis-2.9.x.jar:?]
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106) ~[jedis-2.9.x.jar:?]
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:836) ~[commons-pool2-2.2.jar:2.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:434) ~[commons-pool2-2.2.jar:2.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361) ~[commons-pool2-2.2.jar:2.2]
at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.x.jar:?]
... 45 more

登录redis端

3088:M 21 Mar 21:42:24.187 - Accepted xx.xx.xxx.xxx:36064
3088:M 21 Mar 21:42:24.197 - Accepted xx.xx.xxx.xxx:36065
3088:M 21 Mar 21:42:24.212 - Reading from client: Connection reset by peer
3088:M 21 Mar 21:42:28.481 - DB 0: 12407076 keys (0 volatile) in 16777216 slots HT.
3088:M 21 Mar 21:42:28.482 - 1 clients connected (0 slaves), 1852164712 bytes in use

https://github.com/xetorthio/jedis/issues/1792

最佳答案

Marcos Nils 在 jedis github 中回答了我的问题 - https://github.com/xetorthio/jedis/issues/1792这让我想到了https://github.com/xetorthio/jedis/pull/1211

以前我没有在我的单一主机上创建集群,我可以直接将它用作 2.7.x 中的集群。我运行了以下命令解决了我的问题。

for i in {0..16383}; do bin/redis-cli -h <ipOfHost1> CLUSTER ADDSLOTS $i; done
cluster meet <ip> 6379

关于java - JedisCluster 在 2.7.x 中工作,但在 Jedis 2.9.x 中不工作,JedisConnectionException 和 Connection refused,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49414625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com