Search in sources :

Example 61 with HostAndPort

use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.

the class JedisClusterTest method testRedisClusterMaxRedirections.

@Test(expected = JedisClusterMaxRedirectionsException.class)
public void testRedisClusterMaxRedirections() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    int slot51 = JedisClusterCRC16.getSlot("51");
    // This will cause an infinite redirection loop
    node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
    jc.set("51", "foo");
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 62 with HostAndPort

use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.

the class JedisClusterTest method testCalculateConnectionPerSlot.

@Test
public void testCalculateConnectionPerSlot() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    jc.set("foo", "bar");
    jc.set("test", "test");
    assertEquals("bar", node3.get("foo"));
    assertEquals("test", node2.get("test"));
    JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    jc2.set("foo", "bar");
    jc2.set("test", "test");
    assertEquals("bar", node3.get("foo"));
    assertEquals("test", node2.get("test"));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 63 with HostAndPort

use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.

the class JedisClusterTest method testLocalhostNodeNotAddedWhen127Present.

@Test
public void testLocalhostNodeNotAddedWhen127Present() {
    HostAndPort localhost = new HostAndPort("localhost", 7379);
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    // cluster node is defined as 127.0.0.1; adding localhost should work,
    // but shouldn't show up.
    jedisClusterNode.add(localhost);
    JedisPoolConfig config = DEFAULT_CONFIG;
    config.setMaxTotal(1);
    JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
    assertEquals(3, clusterNodes.size());
    assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost)));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 64 with HostAndPort

use of redis.clients.jedis.HostAndPort in project transporter by wang4ever.

the class JedisClusterFactoryBean method parseHostAndPort.

private Set<HostAndPort> parseHostAndPort() throws Exception {
    try {
        Properties properties = PropertyHolder.getProperties();
        Set<HostAndPort> haps = new HashSet<HostAndPort>();
        for (Object key : properties.keySet()) {
            if (!((String) key).startsWith(addrKeyPrefix))
                continue;
            String val = (String) properties.get(key);
            boolean isIpPort = p.matcher(val).matches();
            if (!isIpPort)
                throw new IllegalArgumentException("ip 或 port 不合法");
            String[] ipAndPort = val.split(":");
            HostAndPort hap = new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
            if (logger.isInfoEnabled())
                logger.info("Redis cluster(node): {}", hap);
            haps.add(hap);
        }
        return haps;
    } catch (IllegalArgumentException ex) {
        throw ex;
    } catch (Exception e) {
        throw new Exception("解析 jedis 配置文件失败", e);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Properties(java.util.Properties) HashSet(java.util.HashSet)

Example 65 with HostAndPort

use of redis.clients.jedis.HostAndPort in project oxCore by GluuFederation.

the class RedisStandaloneProvider method create.

public void create() {
    LOG.debug("Starting RedisStandaloneProvider ...");
    try {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(1000);
        poolConfig.setMinIdle(2);
        HostAndPort hostAndPort = RedisClusterProvider.hosts(redisConfiguration.getServers()).iterator().next();
        pool = new JedisPool(poolConfig, hostAndPort.getHost(), hostAndPort.getPort());
        testConnection();
        LOG.debug("RedisStandaloneProvider started.");
    } catch (Exception e) {
        throw new IllegalStateException("Error starting RedisStandaloneProvider", e);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)102 Test (org.junit.Test)42 HashSet (java.util.HashSet)35 JedisCluster (redis.clients.jedis.JedisCluster)35 Jedis (redis.clients.jedis.Jedis)25 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)12 Before (org.junit.Before)9 JedisPool (redis.clients.jedis.JedisPool)9 ArrayList (java.util.ArrayList)8 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 Properties (java.util.Properties)3