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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations