use of org.springframework.data.redis.connection.RedisClusterConfiguration in project Sermant by huaweicloud.
the class RedisConfig method lettuceConnectionFactoryUvPv.
/**
* 设置重试
*
* @return lettuce工厂
* @throws Exception
*/
@Bean(destroyMethod = "destroy")
public LettuceConnectionFactory lettuceConnectionFactoryUvPv() throws Exception {
List<String> clusterNodes = redisProperties.getCluster().getNodes();
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
if (clusterNodes != null && !clusterNodes.isEmpty()) {
clusterConfiguration.setClusterNodes(setClusterNodes(clusterNodes));
clusterConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
// 判断是否设置了指定参数,没有设置添加默认值
Integer maxRedirects = redisProperties.getCluster().getMaxRedirects();
clusterConfiguration.setMaxRedirects(maxRedirects == null ? MAX_REDIRECTS_DEFAULT : maxRedirects);
int maxIdle = redisProperties.getLettuce().getPool().getMaxIdle();
poolConfig.setMaxIdle(maxIdle != 0 ? maxIdle : MAX_IDLE_DEFAULT);
int minIdle = redisProperties.getLettuce().getPool().getMinIdle();
poolConfig.setMinIdle(minIdle != 0 ? minIdle : MIN_IDLE_DEFAULT);
int maxTotal = redisProperties.getLettuce().getPool().getMaxActive();
poolConfig.setMaxTotal(maxTotal != 0 ? maxTotal : MAX_TOTAL_DEFAULT);
return new LettuceConnectionFactory(clusterConfiguration, getLettuceClientConfiguration(poolConfig));
} else {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setPassword(redisProperties.getPassword());
redisStandaloneConfiguration.setDatabase(redisProperties.getDatabase());
redisStandaloneConfiguration.setPort(redisProperties.getPort());
redisStandaloneConfiguration.setHostName(redisProperties.getHost());
return new LettuceConnectionFactory(redisStandaloneConfiguration, getLettuceClientConfiguration(poolConfig));
}
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration 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);
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project formplayer by dimagi.
the class WebAppContext method jedisConnFactory.
@Bean
public JedisConnectionFactory jedisConnFactory() {
if (redisClusterString != null) {
List<String> nodeList = Arrays.asList(redisClusterString.split(","));
RedisClusterConfiguration config = new RedisClusterConfiguration(nodeList);
config.setPassword(redisPassword);
return new JedisConnectionFactory(config);
} else {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisHostName);
config.setPassword(redisPassword);
return new JedisConnectionFactory(config);
}
}
Aggregations