All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.craft.atom.redis.api.ShardedRedisBuilder Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
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