zoukankan      html  css  js  c++  java
  • 解决测试redis集群时报"java.lang.NumberFormatException: For input string: "7003@17003..7002@17002"等异常

    一、前言

    关于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:65)
        at java.lang.Integer.parseInt(Integer.java:492)
        at java.lang.Integer.valueOf(Integer.java:582)
        at redis.clients.util.ClusterNodeInformationParser.getHostAndPortFromNodeLine(ClusterNodeInformationParser.java:40)
        at redis.clients.util.ClusterNodeInformationParser.parse(ClusterNodeInformationParser.java:14)
        at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:40)
        at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:50)
        at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:31)
        at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:17)
        at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:51)
        at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:35)
        at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:26)
        at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:30)
        at com.xwood.redis.cluster.JedisClusterTest.main(JedisClusterTest.java:23)

    客户端代码示例如下:

    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"7001));
            nodes.add(new HostAndPort("192.168.1.204"7002));
            nodes.add(new HostAndPort("192.168.1.204"7003));
            nodes.add(new HostAndPort("192.168.1.204"7004));
            nodes.add(new HostAndPort("192.168.1.204"7005));
            nodes.add(new HostAndPort("192.168.1.204"7006));
             
            JedisCluster cluster new JedisCluster(nodes);
             
            cluster.set("key424""123456");
             
            String result = cluster.get("key424");
             
            System.out.println("cluster=========>"+result);
            cluster.close();
     
        }
     
    }

    二、解决方法

    因jedis-2.7.0.jar版本问题,改为jedis-3.0.1.jar版本就能解决问题,因为redis5.0版本需要客户端相应高版本驱动包

     

     

     

     

     

     

     

  • 相关阅读:
    python3.6.3中html页面转化成pdf
    python3 基于zabbix 自动抓取监控图片
    AWS EC2 云服务器 Red Hat Enterprise Linux Server release 7.4 (Maipo) vnc远程连接教程
    python处理两个json根据序号进行一对一组合
    CentOS6.9 内核升级(2.6.32-696.16.1升级到4.4.101-1.el6.el)
    给List分页
    Quartz的学习记录
    Uri
    Android studio 随笔
    android 随笔之 GridLayout
  • 原文地址:https://www.cnblogs.com/hxun/p/11096362.html
Copyright © 2011-2022 走看看