use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.
the class JedisSentinelTest method sentinelFailover.
@Test
public void sentinelFailover() throws InterruptedException {
Jedis j = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
Jedis j2 = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
try {
List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
HostAndPort currentMaster = new HostAndPort(masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort.get(1)));
JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);
masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort.get(1)));
assertNotEquals(newMaster, currentMaster);
} finally {
j.close();
}
}
use of redis.clients.jedis.HostAndPort in project uavstack by uavorg.
the class DoTestJedisHookProxy method foo3.
@SuppressWarnings("unused")
private static void foo3() {
System.out.println("TEST JedisCluster ======================================================");
JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 6380));
jc.set("foo", "bar");
String val = jc.get("foo");
System.out.println(val);
jc.set("foo1", "bar");
jc.set("foo2", "bar");
jc.set("foo3", "bar");
jc.set("foo4", "bar");
jc.set("foo5", "bar");
jc.del("foo");
jc.del("foo1");
jc.del("foo2");
jc.del("foo3");
jc.del("foo4");
jc.del("foo5");
try {
jc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of redis.clients.jedis.HostAndPort in project oxCore by GluuFederation.
the class RedisClusterProvider method hosts.
public static Set<HostAndPort> hosts(String servers) {
final String[] serverWithPorts = StringUtils.split(servers.trim(), ",");
Set<HostAndPort> set = new HashSet<HostAndPort>();
for (String serverWithPort : serverWithPorts) {
final String[] split = serverWithPort.trim().split(":");
String host = split[0];
int port = Integer.parseInt(split[1].trim());
set.add(new HostAndPort(host, port));
}
return set;
}
use of redis.clients.jedis.HostAndPort in project tomcat-cluster-redis-session-manager by ran-jit.
the class RedisDataCache method getJedisNodes.
/**
* To get jedis nodes
*
* @param hosts
* @param clusterEnabled
* @return
*/
private Collection<? extends Serializable> getJedisNodes(String hosts, boolean clusterEnabled) {
hosts = hosts.replaceAll("\\s", "");
String[] hostPorts = hosts.split(",");
List<String> node = null;
Set<HostAndPort> nodes = null;
for (String hostPort : hostPorts) {
String[] hostPortArr = hostPort.split(":");
if (clusterEnabled) {
nodes = (nodes == null) ? new HashSet<HostAndPort>() : nodes;
nodes.add(new HostAndPort(hostPortArr[0], Integer.valueOf(hostPortArr[1])));
} else {
int port = Integer.valueOf(hostPortArr[1]);
if (!hostPortArr[0].isEmpty() && port > 0) {
node = (node == null) ? new ArrayList<String>() : node;
node.add(hostPortArr[0]);
node.add(String.valueOf(port));
break;
}
}
}
return clusterEnabled ? nodes : node;
}
use of redis.clients.jedis.HostAndPort in project weicoder by wdcode.
the class JedisClusterFactory method newInstance.
@Override
public JedisCluster newInstance(String name) {
// 实例化Jedis配置
JedisPoolConfig config = new JedisPoolConfig();
// 设置属性
config.setMaxTotal(RedisParams.getMaxTotal(name));
config.setMaxIdle(RedisParams.getMaxIdle(name));
config.setMaxWaitMillis(RedisParams.getMaxWait(name));
// 服务器节点
Set<HostAndPort> nodes = Sets.newSet();
for (String server : RedisParams.getCluster(name)) {
String[] s = StringUtil.split(server, StringConstants.COLON);
nodes.add(new HostAndPort(s[0], Conversion.toInt(s[1])));
}
// 生成JedisCluster
return new JedisCluster(nodes, 3000, 3000, 5, RedisParams.getPassword(name), config);
}
Aggregations