JedisCluster 链接redis集群

摘要:
redis.clients<版本>/版本>config=newJedisPoolConfig();//设置超时配置。setTestOnBorrow(真);jedisClusterNode.add(newHostAndPort(“192.168.246.128”;

先贴代码:

<!-- 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

免责声明:文章转载自《JedisCluster 链接redis集群》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇FFmpeg解码H264及swscale缩放详解Java 程序员常用的个Linux命令下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Asp.net mvc与PHP的Session共享的实现

最近在做的一个ASP.NET MVC的项目,要用到第三方的php系统,为了实现两个系统的互联互通。决定将两者的session打通共享。让asp.net mvc 和php 都能正常访问和修改Session内容。 在决定实现之前,先搜索了一下院子里有没有相类似的文章,对于跨语言的程序互通,有两种方案: (1) SSO单点登录,其实就是把用户名和密码传给另一个系...

Axios源码阅读笔记#1 默认配置项

Promise based HTTP client for the browser and node.js 这是 Axios 的定义,Axios 是基于 Promise,用于HTTP客户端——浏览器和 node.js 的库 。Github:https://github.com/mzabriskie/axios。 官方文档中 Axios 的 feature...

solr的配置文件及其含义

solr与.net系列课程(二)solr的配置文件及其含义        solr与.net系列课程(二)solr的配置文件及其含义        本节内容还是不会涉及到.net与数据库的内容,但是不要着急,这都是学时solr必学要掌握的东西,solr可不是像其他的dll文件一样,只需要引用就能调出方法与数据的,你不配置好是无法使用,前两节主要是起铺垫...

BUI 框架使用指南

  指南说明:只适用于对框架的剥离 如果不需要剥离则原来的东西直接粘贴就行  在主界面中使用时需要加入一下引用bui.js jquery.js config.js 末尾的文件 BUI.use(位置1, function ()  其中位置一需要填写你的main-min.js 文件所在的路径以及main的文件名 例如我的文件在Resouce/JS/main-...

manjaro安装anaconda

安装 yay -S anaconda 配置环境变量 # 添加到 /etc/profile 或者 ~/.bashrc export PATH=$PATH:/opt/anaconda/bin/ 配置conda conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk...

bootstrap-table的一些基本使用及表内编辑的实现

最近工作需要接触了bootstrap-table 所以研究了一下,并做了笔记,红色位置要特别注意  前端主要使用了 jquery bootstrap-table  bootstrap-edittable  bootstrap-table-edittable.js   1)首页我们需要先引用css及js文件 <!---bootstrap使用的是3--&...