package com.test;

import java.util.ArrayList;
import java.util.List; import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool; public class RedisShardPoolTest { static ShardedJedisPool pool; static{
JedisPoolConfig config =new JedisPoolConfig();//Jedis池配置
config.setMaxActive(500);//最大活动的对象个数
config.setMaxIdle(1000 * 60);//对象最大空闲时间
config.setMaxWait(1000 * 10);//获取对象时最大等待时间
config.setTestOnBorrow(true);
String hostA = "192.168.0.100";
int portA = 6379;
String hostB = "192.168.0.115";
int portB = 6379;
List<JedisShardInfo> jdsInfoList =new ArrayList<JedisShardInfo>(2);
JedisShardInfo infoA = new JedisShardInfo(hostA, portA);
infoA.setPassword("admin");
JedisShardInfo infoB = new JedisShardInfo(hostB, portB);
infoB.setPassword("admin");
jdsInfoList.add(infoA);
jdsInfoList.add(infoB);
pool =new ShardedJedisPool(config, jdsInfoList);
} /** * @param args */ public static void main(String[] args) {
for(int i=0; i<100; i++){
String key = generateKey();
ShardedJedis jds = null;
try {
jds = pool.getResource();
System.out.println(key+":"+jds.getShard(key).getClient().getHost());
System.out.println(jds.set(key,Math.random()+""));
} catch (Exception e) {
e.printStackTrace();
} finally {
pool.returnResource(jds);
}
}
} private static int index = 1;
public static String generateKey(){
return String.valueOf(Thread.currentThread().getId())+"_"+(index++);
}
}

(转)ShardedJedisPool的使用的更多相关文章

  1. Redis客户端之Spring整合Jedis,ShardedJedisPool集群配置

    Jedis设计 Jedis作为推荐的java语言redis客户端,其抽象封装为三部分: 对象池设计:Pool,JedisPool,GenericObjectPool,BasePoolableObjec ...

  2. redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置

    http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...

  3. ShardedJedisPool的使用

    package com.test; import java.util.ArrayList; import java.util.List; import redis.clients.jedis.Jedi ...

  4. 38 一次 redis 连接泄露的原因 以及 ShardedJedisPool

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u011039332/article/details/85381051前言 这个是接着 上次的 这篇文 ...

  5. shardedJedisPool工具类

    这里使用的是ShardedJedisPool,而不是RedisTemplate 1.配置文件 <?xml version="1.0" encoding="UTF-8 ...

  6. jedis的ShardedJedisPool链接池的扩容问题

    回顾上一篇文章jedis连接池的构建. 我们来分析ShardedJedisPool的基于客户端分片所可能带来的问题:扩容 ShardedJedisPool的节点扩容 .ShardedJedisPool ...

  7. redis分片

    本文是在window环境下测试 什么是分片 当数据量大的时候,把数据分散存入多个数据库中,减少单节点的连接压力,实现海量数据存储 那么当多个请求来取数据时,如何知道数据在哪个redis呢,redis有 ...

  8. Redis集群(八):Redis Sharding集群

    一.Redis目前的集群方案主要有两种:Redis Sharding和Redis Cluster 1.Redis Sharding:3.0以前基本上使用分片实现集群,目前主流方案,客户端实现 2.Re ...

  9. shared jedis 在spring中的配置

    redis 属性文件配置: redis.host=xx.xx.xx.xx redis.port=6379 #redis.pass=xxxxx redis.maxIdle=10000 redis.max ...

随机推荐

  1. Mac 下面 apache 不解析PHP(or PHP 版本不对)的解决办法

    Mac 升级到 EI Caption 之后发现 apache 的配置被重置了,记录下解决的步骤: 在 apache2 配置文件中修改 PHP 的扩展路径即可: vi /etc/apache2/http ...

  2. Google开源库-Volley的使用

    一.什么是Volley? Volley is an HTTP library that makes networking for Android apps easier and most import ...

  3. Alpha阶段第一次Scrum Meeting

    Scrum Meeting   Alpha 情况简述 Alpha阶段第一次Scrum Meeting 敏捷开发起始时间 2016/10/18 00:00 敏捷开发终止时间 2016/10/20 00: ...

  4. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  5. Linux多安全策略和动态安全策略框架演示验证方案及结果分析

    3演示验证方案及结果分析3.1演示验证方案3.1.1验证目标该方案主要用于验证采用Flask体系结构实现的SELinux对系统的防护过程及相应的防护原理.3.1.2验证环境操作系统:启用了SELinu ...

  6. WebService如何调试及测试工具

    http://www.cnblogs.com/zfanlong1314/archive/2012/04/06/2434788.html 通常,我们在Visual Studio里调试ASP.NET网站, ...

  7. 整合s2sh,实现页面操作数据库

    先说点废话 s2sh,就是struts2,spring,hibernate:s2作为表现层和控制器,hibernate作为持久层,spring作为业务层(充分应用IOC和AOP).其实业务还是业务,只 ...

  8. Google Map API V3开发(6) 代码

    Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...

  9. Java数据结构——字典树TRIE

    又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种. 典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计. 它的优点是:利用字符串的公共 ...

  10. Easymake

    Easymake太好用了,偷懒神器,强力推荐. 一.根目录下的easymake.mk就是makefile模板,我们自定义的makefile只需要包含这个模板即可 include ../../easym ...