【文件属性】:
文件名称:jedis分片选择库,jedis动态过滤无效服务器
文件大小:138KB
文件格式:JAR
更新时间:2018-01-13 05:15:50
jedis
1 jedis分片支持数据库 2 动态的将有故障的服务器过滤掉
使用实例
static ShardedJedisPool shareJedisPool;
static List jdsInfoList =new ArrayList();
static{
JedisPoolConfig config =new JedisPoolConfig();//Jedis池配置
config.setMaxActive(Integer.parseInt(PropertyFactory.get("REDIS_SHARD__MAX_ACTIVE")));//最大活动的对象个数
config.setMaxIdle(Integer.parseInt(PropertyFactory.get("REDIS_SHARD__MAX_IDLE")));//对象最大空闲时间
config.setMinIdle(Integer.parseInt(PropertyFactory.get("REDIS_SHARD__MIN_IDLE")));
config.setMaxWait(Integer.parseInt(PropertyFactory.get("REDIS_SHARD__MAX_WAIT")));//获取对象时最大等待时间
config.setTimeBetweenEvictionRunsMillis(Long.parseLong(PropertyFactory.get("REDIS_SHARD__TIME_BETWEEM_EVICTION")));
config.setMinEvictableIdleTimeMillis(Long.parseLong(PropertyFactory.get("REDIS_SHARD__MIN_EVICTABLE_IDLE_TIME")));
config.setTestOnBorrow(true);
config.setWhenExhaustedAction((byte) 0);
int shardNumber=Integer.parseInt(PropertyFactory.get("REDIS_SHARD_NUMBER"));
for(int i=1;i<=shardNumber;i++){
String ip= PropertyFactory.get("REDIS_SHARE_IP_"+i);
String port=PropertyFactory.get("REDIS_SHARE_PORT_"+i);
String dbIndex=PropertyFactory.get("REDIS_SHARE_DBINDEX_"+i);
JedisShardInfo info = new JedisDBShardInfo(ip, Integer.parseInt(port),Integer.parseInt(dbIndex));
jdsInfoList.add(info);
}
shareJedisPool =new ShardedJedisPool(config, jdsInfoList);
}