Search in sources :

Example 66 with HostAndPort

use of redis.clients.jedis.HostAndPort in project jeesuite-libs by vakinge.

the class JedisClusterProvider method parseHostAndPort.

private Set<HostAndPort> parseHostAndPort(String[] servers) {
    try {
        Set<HostAndPort> haps = new HashSet<HostAndPort>();
        for (String part : servers) {
            String[] ipAndPort = part.split(":");
            HostAndPort hap = new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
            haps.add(hap);
        }
        return haps;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) HashSet(java.util.HashSet)

Example 67 with HostAndPort

use of redis.clients.jedis.HostAndPort in project duangframework by tcrct.

the class JedisClusterPoolUtils method createJedisPool.

/**
 * 建立连接池 真实环境,一般把配置参数缺抽取出来。
 */
private static void createJedisPool() {
    try {
        String[] ipArray = getClusterIps();
        if (ToolsKit.isEmpty(ipArray)) {
            throw new EmptyNullException("ipArray is null");
        }
        // 只给集群里一个实例就可以
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        for (int i = 0; i < ipArray.length; i++) {
            String[] items = ipArray[i].split(":");
            jedisClusterNodes.add(new HostAndPort(items[0], Integer.parseInt(items[1])));
        }
        // 配置信息
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setMaxTotal(10000);
        config.setMaxIdle(500);
        config.setMinIdle(100);
        config.setMaxWaitMillis(5000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        jedisCluster = new JedisCluster(jedisClusterNodes, config);
        if (null != jedisCluster) {
            logger.warn("Connent Redis Cluster:  " + ToolsKit.toJsonString(jedisClusterNodes) + " is Success...");
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("初始化 redis 出错啦...");
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) JedisCluster(redis.clients.jedis.JedisCluster) IOException(java.io.IOException) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) HashSet(java.util.HashSet)

Example 68 with HostAndPort

use of redis.clients.jedis.HostAndPort in project incubator-skywalking by apache.

the class JedisClusterConstructorWithListHostAndPortArgInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    hostAndPortSet = new LinkedHashSet<HostAndPort>();
    interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor();
    hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379));
    hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Before(org.junit.Before)

Example 69 with HostAndPort

use of redis.clients.jedis.HostAndPort in project incubator-skywalking by apache.

the class JedisClusterConstructorWithHostAndPortArgInterceptorTest method onConstruct.

@Test
public void onConstruct() throws Exception {
    interceptor.onConstruct(enhancedInstance, new Object[] { new HostAndPort("127.0.0.1", 6379) });
    verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379");
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Test(org.junit.Test)

Example 70 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)

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