Search in sources :

Example 6 with RedisConnectionConfig

use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.

the class RedisDataSource method getRedisClusterClient.

private RedisClusterClient getRedisClusterClient(RedisConnectionConfig connectionConfig) {
    char[] password = connectionConfig.getPassword();
    String clientName = connectionConfig.getClientName();
    // If any uri is successful for connection, the others are not tried anymore
    List<RedisURI> redisUris = new ArrayList<>();
    for (RedisConnectionConfig config : connectionConfig.getRedisClusters()) {
        RedisURI.Builder clusterRedisUriBuilder = RedisURI.builder();
        clusterRedisUriBuilder.withHost(config.getHost()).withPort(config.getPort()).withTimeout(Duration.ofMillis(connectionConfig.getTimeout()));
        // All redis nodes must have same password
        if (password != null) {
            clusterRedisUriBuilder.withPassword(connectionConfig.getPassword());
        }
        redisUris.add(clusterRedisUriBuilder.build());
    }
    return RedisClusterClient.create(redisUris);
}
Also used : RedisConnectionConfig(com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig) RedisURI(io.lettuce.core.RedisURI) ArrayList(java.util.ArrayList)

Example 7 with RedisConnectionConfig

use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.

the class ClusterModeRedisDataSourceTest method initData.

@Before
public void initData() {
    Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
    RedisConnectionConfig config = RedisConnectionConfig.builder().withRedisCluster(host, redisSentinelPort).build();
    initRedisRuleData();
    ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<>(config, ruleKey, channel, flowConfigParser);
    FlowRuleManager.register2Property(redisDataSource.getProperty());
}
Also used : RedisConnectionConfig(com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig) List(java.util.List)

Example 8 with RedisConnectionConfig

use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.

the class RedisConnectionConfigTest method testRedisSentinelMoreThanOneDuplicateServerSuccess.

@Test
public void testRedisSentinelMoreThanOneDuplicateServerSuccess() {
    String host = "localhost";
    String host2 = "server2";
    int port2 = 1879;
    RedisConnectionConfig redisConnectionConfig = RedisConnectionConfig.Builder.redisSentinel(host).withRedisSentinel(host2, port2).withRedisSentinel(host2, port2).withPassword("211233").build();
    Assert.assertNull(redisConnectionConfig.getHost());
    Assert.assertEquals(3, redisConnectionConfig.getRedisSentinels().size());
}
Also used : RedisConnectionConfig(com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig) Test(org.junit.Test)

Example 9 with RedisConnectionConfig

use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.

the class RedisConnectionConfigTest method testRedisTimeOutPropertySuccess.

@Test
public void testRedisTimeOutPropertySuccess() {
    String host = "localhost";
    long timeout = 70 * 1000;
    RedisConnectionConfig redisConnectionConfig = RedisConnectionConfig.Builder.redis(host).withTimeout(timeout).build();
    Assert.assertEquals(redisConnectionConfig.getTimeout(), timeout);
}
Also used : RedisConnectionConfig(com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig) Test(org.junit.Test)

Example 10 with RedisConnectionConfig

use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.

the class RedisConnectionConfigTest method testRedisClientNamePropertySuccess.

@Test
public void testRedisClientNamePropertySuccess() {
    String host = "localhost";
    String clientName = "clientName";
    RedisConnectionConfig redisConnectionConfig = RedisConnectionConfig.Builder.redis(host).withClientName("clientName").build();
    Assert.assertEquals(redisConnectionConfig.getClientName(), clientName);
}
Also used : RedisConnectionConfig(com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig) Test(org.junit.Test)

Aggregations

RedisConnectionConfig (com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig)14 Test (org.junit.Test)9 List (java.util.List)3 RedisURI (io.lettuce.core.RedisURI)2 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1