use of org.springframework.data.redis.connection.RedisClusterConfiguration in project olive by ClareTung.
the class RedisConfig method secondaryRedisConfig.
/**
* 配置第二个数据源
*/
@Bean("secondaryRedisClusterConfig")
public RedisClusterConfiguration secondaryRedisConfig() {
Map<String, Object> source = new HashMap<>(8);
source.put("spring.redis.cluster.nodes", environment.getProperty("spring.secondaryRedis.cluster.nodes"));
RedisClusterConfiguration redisClusterConfiguration;
redisClusterConfiguration = new RedisClusterConfiguration(new MapPropertySource("RedisClusterConfiguration", source));
redisClusterConfiguration.setPassword(environment.getProperty("spring.redis.password"));
return redisClusterConfiguration;
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project JAVA_LOVE_GO by zhonghuasheng.
the class RedisFactoryConfig method lettuceConnectionFactory.
@Bean
public RedisConnectionFactory lettuceConnectionFactory() {
Map<String, Object> source = new HashMap<String, Object>();
source.put("spring.redis.cluster.nodes", environment.getProperty("spring.redis.cluster.nodes"));
source.put("spring.redis.cluster.max-redirects", environment.getProperty("spring.redis.cluster.max-redirects"));
source.put("spring.redis.timeout", environment.getProperty("spring.redis.timeout"));
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(new MapPropertySource("RedisClusterConfiguration", source));
return new LettuceConnectionFactory(redisClusterConfiguration);
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project cas by apereo.
the class RedisObjectFactory method getClusterConfig.
private static RedisClusterConfiguration getClusterConfig(final BaseRedisProperties redis) {
val redisConfiguration = new RedisClusterConfiguration();
val cluster = redis.getCluster();
cluster.getNodes().stream().filter(nodeConfig -> StringUtils.hasText(nodeConfig.getHost()) && nodeConfig.getPort() > 0 && StringUtils.hasText(nodeConfig.getType())).forEach(nodeConfig -> {
LOGGER.trace("Building redis cluster node for [{}]", nodeConfig);
val nodeBuilder = new RedisNode.RedisNodeBuilder().listeningAt(nodeConfig.getHost(), nodeConfig.getPort()).promotedAs(RedisNode.NodeType.valueOf(nodeConfig.getType().toUpperCase()));
if (StringUtils.hasText(nodeConfig.getReplicaOf())) {
nodeBuilder.replicaOf(nodeConfig.getReplicaOf());
}
if (StringUtils.hasText(nodeConfig.getId())) {
nodeBuilder.withId(nodeConfig.getId());
}
if (StringUtils.hasText(nodeConfig.getName())) {
nodeBuilder.withName(nodeConfig.getName());
}
redisConfiguration.clusterNode(nodeBuilder.build());
});
if (StringUtils.hasText(cluster.getPassword())) {
redisConfiguration.setPassword(cluster.getPassword());
}
if (cluster.getMaxRedirects() > 0) {
redisConfiguration.setMaxRedirects(cluster.getMaxRedirects());
}
return redisConfiguration;
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project spring-boot by spring-projects.
the class RedisAutoConfigurationTests method testRedisConfigurationWithCluster.
@Test
void testRedisConfigurationWithCluster() {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
this.contextRunner.withPropertyValues("spring.redis.cluster.nodes[0]:" + clusterNodes.get(0), "spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)).run((context) -> {
RedisClusterConfiguration clusterConfiguration = context.getBean(LettuceConnectionFactory.class).getClusterConfiguration();
assertThat(clusterConfiguration.getClusterNodes()).hasSize(2);
assertThat(clusterConfiguration.getClusterNodes()).extracting((node) -> node.getHost() + ":" + node.getPort()).containsExactlyInAnyOrder("127.0.0.1:27379", "127.0.0.1:27380");
});
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration 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;
}
Aggregations