io.craft.atom.redis.api.ShardedRedisBuilder Maven / Gradle / Ivy
package io.craft.atom.redis.api;
import io.craft.atom.redis.DefaultShardedRedis;
import java.util.ArrayList;
import java.util.List;
/**
* Builder for {@link ShardedRedis}
*
* @author mindwind
* @version 1.0, Apr 19, 2014
*/
public class ShardedRedisBuilder extends AbstractRedisBuilder {
private String shardstring;
/**
* @param shardstring format string e.g. localhost:6379,localhost:6380,localhost:6381
*/
public ShardedRedisBuilder(String shardstring) {
this.shardstring = shardstring;
}
static String[] parse(String shardstring) {
return shardstring.trim().split(",");
}
@Override
public ShardedRedis build() {
RedisPoolConfig poolConfig = new RedisPoolConfig();
set(poolConfig);
String[] hostports = parse(shardstring);
List shards = new ArrayList(hostports.length);
for (String hostport : hostports) {
Redis redis = new RedisBuilder(hostport).copy(this).build();
shards.add(redis);
}
return new DefaultShardedRedis(shards);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy