错误描述:
本地搭建的redis集群,使用jedis-2.8.0.jar和redis-4.0.6,启动后,在redis-cli客户端使用cluster nodes查找当前节点数据,得到的是:
在Eclipse使用以下测试代码测试:
Set<HostAndPort> nodes = new LinkedHashSet<HostAndPort>();
//添加集群中的节点
nodes.add(new HostAndPort("127.0.0.1", 6379));
nodes.add(new HostAndPort("127.0.0.1", 6380));
nodes.add(new HostAndPort("127.0.0.1", 6381));
nodes.add(new HostAndPort("127.0.0.1", 6382));
nodes.add(new HostAndPort("127.0.0.1", 6383));
nodes.add(new HostAndPort("127.0.0.1", 6384));
JedisCluster cluster = new JedisCluster(nodes);
cluster.set("KTest", "VTest");
System.out.println(cluster.get("KTest"));
try {
cluster.close();
} catch (IOException e) {
e.printStackTrace();
}
在new JedisCluster()时出现错误: java.lang.NumberFormatException: For input string: "6379@16379"
错误截图:
解决方案:将使用的jedis-2.8.0.jar包换成jedis-2.9.0.jar即可。
参考文档:https://ask.csdn.net/questions/645735?sort=votes_count