一、前言
关于redis5.0的集群模式下,通过客户端测试代码调试报"Exception in thread "main" java.lang.NumberFormatException: For input string: "7003@17003..7002@17002"等异常,详情日志如下>>
Exception in thread "main" java.lang.NumberFormatException: For input string: "7003@17003"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:)
at java.lang.Integer.parseInt(Integer.java:)
at java.lang.Integer.valueOf(Integer.java:)
at redis.clients.util.ClusterNodeInformationParser.getHostAndPortFromNodeLine(ClusterNodeInformationParser.java:)
at redis.clients.util.ClusterNodeInformationParser.parse(ClusterNodeInformationParser.java:)
at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:)
at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:)
at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:)
at com.xwood.redis.cluster.JedisClusterTest.main(JedisClusterTest.java:)
客户端代码示例如下:
package com.xwood.redis.cluster;
import java.util.HashSet;
import java.util.Set;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
public class JedisClusterTest {
public static void main(String[] args) {
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("192.168.1.204", ));
nodes.add(new HostAndPort("192.168.1.204", ));
nodes.add(new HostAndPort("192.168.1.204", ));
nodes.add(new HostAndPort("192.168.1.204", ));
nodes.add(new HostAndPort("192.168.1.204", ));
nodes.add(new HostAndPort("192.168.1.204", ));
JedisCluster cluster = new JedisCluster(nodes);
cluster.set("key424", "");
String result = cluster.get("key424");
System.out.println("cluster=========>"+result);
cluster.close();
}
}
二、解决方法
因jedis-2.7.0.jar版本问题,改为jedis-3.0.1.jar版本就能解决问题,因为redis5.0版本需要客户端相应高版本驱动包