一、前言
关于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"@b@ at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)@b@ at java.lang.Integer.parseInt(Integer.java:492)@b@ at java.lang.Integer.valueOf(Integer.java:582)@b@ at redis.clients.util.ClusterNodeInformationParser.getHostAndPortFromNodeLine(ClusterNodeInformationParser.java:40)@b@ at redis.clients.util.ClusterNodeInformationParser.parse(ClusterNodeInformationParser.java:14)@b@ at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:40)@b@ at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:50)@b@ at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:31)@b@ at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:17)@b@ at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:51)@b@ at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:35)@b@ at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:26)@b@ at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:30)@b@ at com.xwood.redis.cluster.JedisClusterTest.main(JedisClusterTest.java:23)
客户端代码示例如下
package com.xwood.redis.cluster;@b@@b@import java.util.HashSet;@b@import java.util.Set;@b@@b@import redis.clients.jedis.HostAndPort;@b@import redis.clients.jedis.JedisCluster;@b@@b@public class JedisClusterTest {@b@@b@ @b@ public static void main(String[] args) {@b@ @b@ Set<HostAndPort> nodes = new HashSet<HostAndPort>();@b@ @b@ nodes.add(new HostAndPort("192.168.1.204", 7001));@b@ nodes.add(new HostAndPort("192.168.1.204", 7002));@b@ nodes.add(new HostAndPort("192.168.1.204", 7003));@b@ nodes.add(new HostAndPort("192.168.1.204", 7004));@b@ nodes.add(new HostAndPort("192.168.1.204", 7005));@b@ nodes.add(new HostAndPort("192.168.1.204", 7006));@b@ @b@ JedisCluster cluster = new JedisCluster(nodes);@b@ @b@ cluster.set("key424", "123456");@b@ @b@ String result = cluster.get("key424");@b@ @b@ System.out.println("cluster=========>"+result);@b@ cluster.close();@b@@b@ }@b@@b@}
二、解决方法
因jedis-2.7.0.jar版本改为jedis-3.0.1.jar版本解决问题,因为redis5.0版本需要客户端相应高版本驱动包