Polish contribution

Closes gh-5128
This commit is contained in:
Stephane Nicoll 2016-02-18 15:08:57 +01:00
parent fc22731420
commit a95568d3e8
4 changed files with 19 additions and 32 deletions

View File

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

View File

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

View File

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

View File

@ -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. spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use.
# REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties]) # 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.
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.nodes= # Comma-separated list of "host:port" pairs to bootstrap from.
spring.redis.database=0 # Database index used by the connection factory. spring.redis.database=0 # Database index used by the connection factory.
spring.redis.host=localhost # Redis server host. spring.redis.host=localhost # Redis server host.
spring.redis.password= # Login password of the redis server. spring.redis.password= # Login password of the redis server.