zoukankan      html  css  js  c++  java
  • JedisCluster 链接redis集群

    先贴代码:

    <!-- redis客户端 -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.8.2</version>
    </dependency>

    //相关代码如下:

    JedisPoolConfig config = new JedisPoolConfig();
    config =new JedisPoolConfig();
           config.setMaxTotal(60000);//设置最大连接数  
           config.setMaxIdle(1000); //设置最大空闲数 
           config.setMaxWaitMillis(3000);//设置超时时间  
           config.setTestOnBorrow(true);


    // 集群结点
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7001")));
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7002")));
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7003")));
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7004")));
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7005")));
    jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7006")));

    JedisCluster jc = new JedisCluster(jedisClusterNode, config);
    //JedisCluster jc = new JedisCluster(jedisClusterNode);
    jc.set("name", "zhangsan");
    String value = jc.get("name");
    System.out.println(value);

     注意事项

    redis配置文件中  bind配置注释掉  或者bind 0.0.0.0  表示所有的服务器都可以连接

    如果配置为  bind  127.0.0.1  会报Could not get a resource from the pool 错误

    创建集群命令为./redis-trib.rb create --replicas 1 45.78.76.17:7001 45.78.76.17:7002 45.78.76.17:7003 45.78.76.17:7004 45.78.76.17:7005 45.78.76.17:7006 45.78.76.17:7007 45.78.76.17:7008

    其中  45.78.76.17为本机IP

  • 相关阅读:
    多线程GCD(二)
    多线程
    Runtime & Runloop
    MTK android 重启测试脚本
    ubuntu samba 配置简介
    Gerrit使用简介
    MTK andorid从底层到上层添加驱动
    MTK GPIO 新增变量配置
    MT6755 使用R63350 IC 出现唤醒概率性闪白,并导致ESD FAIL
    android L版本AAL新架构
  • 原文地址:https://www.cnblogs.com/moxiaotao/p/10069725.html
Copyright © 2011-2022 走看看