Polish contribution

Closes gh-5128
pull/5052/merge
Stephane Nicoll 9 years ago
parent fc22731420
commit a95568d3e8

@ -110,48 +110,40 @@ public class RedisAutoConfiguration {
}
/**
* Create {@link RedisClusterConfiguration} from {@link RedisProperties.Cluster}.
*
*
* @return {@literal null} if no {@link RedisProperties.Cluster} set.
*
* Create a {@link RedisClusterConfiguration} if necessary.
* @return {@literal null} if no cluster settings are set.
*/
protected final RedisClusterConfiguration getClusterConfiguration() {
if (this.clusterConfiguration != null) {
return this.clusterConfiguration;
}
if (this.properties.getCluster() == null) {
return null;
}
Cluster clusterProperties = this.properties.getCluster();
RedisClusterConfiguration config = new RedisClusterConfiguration(
clusterProperties.getNodes());
if (clusterProperties.getMaxRedirects() != null) {
config.setMaxRedirects(config.getMaxRedirects().intValue());
config.setMaxRedirects(config.getMaxRedirects());
}
return config;
}
private List<RedisNode> createSentinels(Sentinel sentinel) {
List<RedisNode> sentinels = new ArrayList<RedisNode>();
String nodes = sentinel.getNodes();
for (String node : StringUtils.commaDelimitedListToStringArray(nodes)) {
List<RedisNode> nodes = new ArrayList<RedisNode>();
for (String node : StringUtils.commaDelimitedListToStringArray(sentinel.getNodes())) {
try {
String[] parts = StringUtils.split(node, ":");
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
sentinels.add(new RedisNode(parts[0], Integer.valueOf(parts[1])));
nodes.add(new RedisNode(parts[0], Integer.valueOf(parts[1])));
}
catch (RuntimeException ex) {
throw new IllegalStateException(
"Invalid redis sentinel " + "property '" + node + "'", ex);
}
}
return sentinels;
return nodes;
}
}
@ -172,15 +164,12 @@ public class RedisAutoConfiguration {
}
private JedisConnectionFactory createJedisConnectionFactory() {
if (getSentinelConfig() != null) {
return new JedisConnectionFactory(getSentinelConfig());
}
if (getClusterConfiguration() != null) {
return new JedisConnectionFactory(getClusterConfiguration());
}
return new JedisConnectionFactory();
}
}
@ -201,7 +190,6 @@ public class RedisAutoConfiguration {
}
private JedisConnectionFactory createJedisConnectionFactory() {
JedisPoolConfig poolConfig = this.properties.getPool() != null ? jedisPoolConfig()
: new JedisPoolConfig();
@ -211,7 +199,6 @@ public class RedisAutoConfiguration {
if (getClusterConfiguration() != null) {
return new JedisConnectionFactory(getClusterConfiguration(), poolConfig);
}
return new JedisConnectionFactory(poolConfig);
}

@ -118,7 +118,7 @@ public class RedisProperties {
}
public Cluster getCluster() {
return cluster;
return this.cluster;
}
public void setCluster(Cluster cluster) {
@ -186,29 +186,28 @@ public class RedisProperties {
public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
}
/**
* Cluster properties.
*
*/
public static class Cluster {
/**
* List of host:port pairs. This setting points to an "initial" list of cluster
* nodes and is required to have at least one entry.
* Comma-separated list of "host:port" pairs to bootstrap from. This represents
* an "initial" list of cluster nodes and is required to have at least one entry.
*/
private List<String> nodes;
/**
* Maximum number of "redirects". Limits the number of redirects to follow when
* executing commands across the cluster. Leave empty to use driver specific
* settings.
* Maximum number of redirects to follow when executing commands across the
* cluster.
*/
private Integer maxRedirects;
public List<String> getNodes() {
return nodes;
return this.nodes;
}
public void setNodes(List<String> nodes) {
@ -216,12 +215,13 @@ public class RedisProperties {
}
public Integer getMaxRedirects() {
return maxRedirects;
return this.maxRedirects;
}
public void setMaxRedirects(Integer maxRedirects) {
this.maxRedirects = maxRedirects;
}
}
/**
@ -254,5 +254,6 @@ public class RedisProperties {
public void setNodes(String nodes) {
this.nodes = nodes;
}
}
}

@ -106,7 +106,6 @@ public class RedisAutoConfigurationTests {
@Test
public void testRedisConfigurationWithCluster() throws Exception {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
if (isAtLeastOneNodeAvailable(clusterNodes)) {
load("spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),

@ -685,8 +685,8 @@ content into your application; rather pick only the properties that you need.
spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use.
# REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties])
spring.redis.cluster.nodes= # List of host:port pairs pointing to an intial collection of cluster nodes. Requires at least one node to connect to the cluster.
spring.redis.cluster.max-redirects= # Maximum number of redirects to follow when executing commands across the cluster. Leave empty to use the driver specific value.
spring.redis.cluster.max-redirects= # Maximum number of redirects to follow when executing commands across the cluster.
spring.redis.cluster.nodes= # Comma-separated list of "host:port" pairs to bootstrap from.
spring.redis.database=0 # Database index used by the connection factory.
spring.redis.host=localhost # Redis server host.
spring.redis.password= # Login password of the redis server.

Loading…
Cancel
Save