Search in sources :

Example 11 with HostAndPort

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();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) Test(org.junit.Test)

Example 12 with HostAndPort

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();
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) IOException(java.io.IOException)

Example 13 with HostAndPort

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;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) HashSet(java.util.HashSet)

Example 14 with HostAndPort

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;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 15 with HostAndPort

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);
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)95 Test (org.junit.Test)42 JedisCluster (redis.clients.jedis.JedisCluster)33 HashSet (java.util.HashSet)31 Jedis (redis.clients.jedis.Jedis)24 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)10 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 JedisPool (redis.clients.jedis.JedisPool)7 ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)6 AppDesc (com.sohu.cache.entity.AppDesc)5 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)5 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JedisPubSub (redis.clients.jedis.JedisPubSub)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JSONObject (com.alibaba.fastjson.JSONObject)2