use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project incubator-shenyu by apache.
the class RateLimiterPluginDataHandlerTest method redisSentinelConfigurationPropertyTest.
/**
* redisSentinelConfiguration property test case.
*/
@Test
public void redisSentinelConfigurationPropertyTest() {
RedisSentinelConfiguration configuration = ReflectionTestUtils.invokeMethod(rateLimiterPluginDataHandler, "redisSentinelConfiguration", generateRateLimiterConfig("localhost:2181;localhost:2182"));
assertNotNull(configuration);
assertEquals(DATABASE_TEST_VALUE, configuration.getDatabase());
assertEquals(RedisPassword.of(PASSWORD_TEST_VALUE), configuration.getPassword());
assertEquals(Collections.unmodifiableSet(Sets.newHashSet(generateRedisNode(PORT_TEST_VALUE_1), generateRedisNode(PORT_TEST_VALUE_2))), configuration.getSentinels());
}
use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project cas by apereo.
the class RedisObjectFactory method getSentinelConfig.
private static RedisSentinelConfiguration getSentinelConfig(final BaseRedisProperties redis) {
LOGGER.debug("Setting Redis with Sentinel configuration on master [{}]", redis.getSentinel().getMaster());
val sentinelConfig = new RedisSentinelConfiguration().master(redis.getSentinel().getMaster());
LOGGER.debug("Sentinel nodes configured are [{}]", redis.getSentinel().getNode());
sentinelConfig.setSentinels(createRedisNodesForProperties(redis));
sentinelConfig.setDatabase(redis.getDatabase());
if (StringUtils.hasText(redis.getPassword())) {
sentinelConfig.setPassword(RedisPassword.of(redis.getPassword()));
}
return sentinelConfig;
}
use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project nifi by apache.
the class RedisUtils method createConnectionFactory.
public static JedisConnectionFactory createConnectionFactory(final PropertyContext context, final ComponentLog logger) {
final String redisMode = context.getProperty(RedisUtils.REDIS_MODE).getValue();
final String connectionString = context.getProperty(RedisUtils.CONNECTION_STRING).evaluateAttributeExpressions().getValue();
final Integer dbIndex = context.getProperty(RedisUtils.DATABASE).evaluateAttributeExpressions().asInteger();
final String password = context.getProperty(RedisUtils.PASSWORD).evaluateAttributeExpressions().getValue();
final Integer timeout = context.getProperty(RedisUtils.COMMUNICATION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
final JedisPoolConfig poolConfig = createJedisPoolConfig(context);
JedisConnectionFactory connectionFactory;
if (RedisUtils.REDIS_MODE_STANDALONE.getValue().equals(redisMode)) {
final JedisShardInfo jedisShardInfo = createJedisShardInfo(connectionString, timeout, password);
logger.info("Connecting to Redis in standalone mode at " + connectionString);
connectionFactory = new JedisConnectionFactory(jedisShardInfo);
} else if (RedisUtils.REDIS_MODE_SENTINEL.getValue().equals(redisMode)) {
final String[] sentinels = connectionString.split("[,]");
final String sentinelMaster = context.getProperty(RedisUtils.SENTINEL_MASTER).evaluateAttributeExpressions().getValue();
final RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration(sentinelMaster, new HashSet<>(getTrimmedValues(sentinels)));
final JedisShardInfo jedisShardInfo = createJedisShardInfo(sentinels[0], timeout, password);
logger.info("Connecting to Redis in sentinel mode...");
logger.info("Redis master = " + sentinelMaster);
for (final String sentinel : sentinels) {
logger.info("Redis sentinel at " + sentinel);
}
connectionFactory = new JedisConnectionFactory(sentinelConfiguration, poolConfig);
connectionFactory.setShardInfo(jedisShardInfo);
} else {
final String[] clusterNodes = connectionString.split("[,]");
final Integer maxRedirects = context.getProperty(RedisUtils.CLUSTER_MAX_REDIRECTS).asInteger();
final RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(getTrimmedValues(clusterNodes));
clusterConfiguration.setMaxRedirects(maxRedirects);
logger.info("Connecting to Redis in clustered mode...");
for (final String clusterNode : clusterNodes) {
logger.info("Redis cluster node at " + clusterNode);
}
connectionFactory = new JedisConnectionFactory(clusterConfiguration, poolConfig);
}
connectionFactory.setUsePool(true);
connectionFactory.setPoolConfig(poolConfig);
connectionFactory.setDatabase(dbIndex);
connectionFactory.setTimeout(timeout);
if (!StringUtils.isBlank(password)) {
connectionFactory.setPassword(password);
}
// need to call this to initialize the pool/connections
connectionFactory.afterPropertiesSet();
return connectionFactory;
}
use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project incubator-shenyu by apache.
the class RateLimiterPluginDataHandler method redisSentinelConfiguration.
private RedisSentinelConfiguration redisSentinelConfiguration(final RateLimiterConfig rateLimiterConfig) {
RedisSentinelConfiguration config = new RedisSentinelConfiguration();
config.master(rateLimiterConfig.getMaster());
config.setSentinels(createRedisNode(rateLimiterConfig.getUrl()));
if (rateLimiterConfig.getPassword() != null) {
config.setPassword(RedisPassword.of(rateLimiterConfig.getPassword()));
}
config.setDatabase(rateLimiterConfig.getDatabase());
return config;
}
use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project jag-file-submission by bcgov.
the class CacheConfiguration method jedisConnectionFactory.
/**
* Configure the JedisConnectionFactory
* @param properties The redis properties
* @return a JedisConnectionFactory
*/
@Bean
public JedisConnectionFactory jedisConnectionFactory(RedisProperties properties) {
if (properties.getCluster() != null) {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(properties.getCluster().getNodes());
redisClusterConfiguration.setPassword(properties.getPassword());
if (properties.getCluster().getMaxRedirects() != null)
redisClusterConfiguration.setMaxRedirects(properties.getCluster().getMaxRedirects());
return new JedisConnectionFactory(redisClusterConfiguration);
}
if (properties.getSentinel() != null) {
RedisSentinelConfiguration redisSantinelConfiguration = new RedisSentinelConfiguration();
redisSantinelConfiguration.setMaster(properties.getSentinel().getMaster());
redisSantinelConfiguration.setSentinels(createSentinels(properties.getSentinel()));
redisSantinelConfiguration.setPassword(properties.getPassword());
return new JedisConnectionFactory(redisSantinelConfiguration);
}
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(properties.getHost());
redisStandaloneConfiguration.setPort(properties.getPort());
redisStandaloneConfiguration.setPassword(properties.getPassword());
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
Aggregations