use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.
the class RedisDataSource method getRedisSentinelClient.
private RedisClient getRedisSentinelClient(RedisConnectionConfig connectionConfig) {
char[] password = connectionConfig.getPassword();
String clientName = connectionConfig.getClientName();
RedisURI.Builder sentinelRedisUriBuilder = RedisURI.builder();
for (RedisConnectionConfig config : connectionConfig.getRedisSentinels()) {
sentinelRedisUriBuilder.withSentinel(config.getHost(), config.getPort());
}
if (password != null) {
sentinelRedisUriBuilder.withPassword(connectionConfig.getPassword());
}
if (StringUtil.isNotEmpty(connectionConfig.getClientName())) {
sentinelRedisUriBuilder.withClientName(clientName);
}
sentinelRedisUriBuilder.withSentinelMasterId(connectionConfig.getRedisSentinelMasterId()).withTimeout(connectionConfig.getTimeout(), TimeUnit.MILLISECONDS);
return RedisClient.create(sentinelRedisUriBuilder.build());
}
use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.
the class RedisConnectionConfigTest method testRedisClusterDefaultPortSuccess.
@Test
public void testRedisClusterDefaultPortSuccess() {
String host = "localhost";
RedisConnectionConfig redisConnectionConfig = RedisConnectionConfig.Builder.redisCluster(host).withPassword("211233").build();
Assert.assertNull(redisConnectionConfig.getHost());
Assert.assertEquals(1, redisConnectionConfig.getRedisClusters().size());
Assert.assertEquals(RedisConnectionConfig.DEFAULT_CLUSTER_PORT, redisConnectionConfig.getRedisClusters().get(0).getPort());
}
use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.
the class RedisConnectionConfigTest method testRedisClusterMoreThanOneServerSuccess.
@Test
public void testRedisClusterMoreThanOneServerSuccess() {
String host = "localhost";
String host2 = "server2";
int port1 = 1879;
int port2 = 1880;
RedisConnectionConfig redisConnectionConfig = RedisConnectionConfig.Builder.redisCluster(host, port1).withRedisCluster(host2, port2).build();
Assert.assertNull(redisConnectionConfig.getHost());
Assert.assertEquals(2, redisConnectionConfig.getRedisClusters().size());
}
use of com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig in project Sentinel by alibaba.
the class SentinelModeRedisDataSourceTest method initData.
@Before
public void initData() {
Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
RedisConnectionConfig config = RedisConnectionConfig.builder().withRedisSentinel(host, redisSentinelPort).withRedisSentinel(host, redisSentinelPort).withSentinelMasterId(redisSentinelMasterId).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 StandaloneRedisDataSourceTest method buildResource.
@Before
public void buildResource() {
try {
// Bind to a random port.
server = RedisServer.newRedisServer();
server.start();
} catch (IOException e) {
e.printStackTrace();
}
Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
client = RedisClient.create(RedisURI.create(server.getHost(), server.getBindPort()));
RedisConnectionConfig config = RedisConnectionConfig.builder().withHost(server.getHost()).withPort(server.getBindPort()).build();
initRedisRuleData();
ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(config, ruleKey, channel, flowConfigParser);
FlowRuleManager.register2Property(redisDataSource.getProperty());
}
Aggregations