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

com.yuweix.kuafu.data.springboot.jedis.RedisClusterNode Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.yuweix.kuafu.data.springboot.jedis;


import redis.clients.jedis.HostAndPort;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;


/**
 * @author yuwei
 */
public abstract class RedisClusterNode {
	private static final Pattern pattern = Pattern.compile("^.+[:]\\d{1,5}\\s*$");

	protected abstract List getNodeList();

	public List getHostAndPortList() {
		List list = new ArrayList<>();
		List nodes = getNodeList();
		if (nodes == null || nodes.size() <= 0) {
			return list;
		}

		for (String node: nodes) {
			boolean isIpPort = pattern.matcher(node).matches();
			if (!isIpPort) {
				throw new IllegalArgumentException("ip 或 port 不合法");
			}

			String[] ipAndPort = node.split(":");
			HostAndPort hap = new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
			list.add(hap);
		}
		return list;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy