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

io.craft.atom.redis.api.MasterSlaveShardedRedisBuilder 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.DefaultMasterSlaveShardedRedis;

import java.util.ArrayList;
import java.util.List;



/**
 * Builder for {@link MasterSlaveShardedRedis}
 * 
 * @author mindwind
 * @version 1.0, Apr 19, 2014
 */
public class MasterSlaveShardedRedisBuilder extends AbstractRedisBuilder {
	
	
	private String masterslaveshardstring;

	
	/**
	 * @param masterslaveshardstring format string e.g. localhost:6379-localhost:6380,localhost:6389-localhost:6390
	 */
	public MasterSlaveShardedRedisBuilder(String masterslaveshardstring) {
		this.masterslaveshardstring = masterslaveshardstring;
	}
	
	
	static String[] parse(String masterslaveshardstring) {
		return masterslaveshardstring.trim().split(",");
	}
	
	
	@Override
	public MasterSlaveShardedRedis build() {
		RedisPoolConfig  poolConfig = new RedisPoolConfig();
		set(poolConfig);
		String[] masterslavestrings = parse(masterslaveshardstring);
		
		List shards = new ArrayList();
		for (String masterslavestring : masterslavestrings) {
			MasterSlaveRedis msr = new MasterSlaveRedisBuilder(masterslavestring).copy(this).build();
			shards.add(msr);
		}
		return new DefaultMasterSlaveShardedRedis(shards);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy