本地jedis版本过低踩的坑

环境:jedis-2.7.3;redis-4.0.2

客户端使用JedisCluster连接redis集群报错如下:

本地jedis版本过低踩的坑_第1张图片

原因:jedis通过JedisClusterInfoCache.discoverClusterNodesAndSlots方法获取集群节点信息,内部实现

public void discoverClusterNodesAndSlots(Jedis jedis) {
        this.w.lock();

        try {
            this.nodes.clear();
            this.slots.clear();
            String localNodes = jedis.clusterNodes();
            String[] arr$ = localNodes.split("\n");
            int len$ = arr$.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String nodeInfo = arr$[i$];
                ClusterNodeInformation clusterNodeInfo = nodeInfoParser.parse(nodeInfo, new HostAndPort(jedis.getClient().getHost(), jedis.getClient().getPort()));
                HostAndPort targetNode = clusterNodeInfo.getNode();
                this.setNodeIfNotExist(targetNode);
                this.assignSlotsToNode(clusterNodeInfo.getAvailableSlots(), targetNode);
            }
        } finally {
            this.w.unlock();
        }

    }
关键就是这个jedis.clusterNodes()方法,它会调用cluster nodes指令,而redis4.0以上该指令会将其通信端口一并输出,注意后面的@18006

本地jedis版本过低踩的坑_第2张图片

之前的redis版本作为比较:

2a0ebb6d554fc8aa8a936bc0c0c2a6583425cf7e 119.254.166.136:7031 myself,master - 0 0 1 connected 0-5460

6f7119b06bb3316119f0bed3f793c2ce87983566 119.254.166.136:7036 slave

6fd9a873b29f5e9a61756606ececa4a953a11db7 0 1479278388635 6 connected

1b42b9d25779ccd5555fb804d01ddfbdd20635bf 119.254.166.136:7032 master - 0 1479278389637 2 connected 5461-10922

e22f9b0d7cb3fdb932926a1b4d9c3140e70255eb 119.254.166.136:7034 slave 2a0ebb6d554fc8aa8a936bc0c0c2a6583425cf7e 0 1479278390639 4 connected

cd480d1b437ad323ae3e15e548db8faf43a5d766 119.254.166.136:7035 slave 1b42b9d25779ccd5555fb804d01ddfbdd20635bf 0 1479278385630 5 connected

6fd9a873b29f5e9a61756606ececa4a953a11db7 119.254.166.136:7033 master - 0 1479278386632 3 connected 10923-16383


结果就是报NumberFormatException

解决:直接将jedis版本升至最高,目前是jedis-2.9.0,问题解决!

没有做其他版本的测试,已知jedis-2.7.3是肯定不行的,2.8版本未知,有兴趣的朋友可以去测试下.....

你可能感兴趣的:(redis)