DATAREDIS-315 - Remove timeout/password from RedisClusterConfiguration.
Removed duplicate configuration options for timeout and password from RedisClusterConfiguration and use the ones provided via the RedisConnectionFactory. Original pull request: #158.
This commit is contained in:
committed by
Mark Paluch
parent
0ac118fcc0
commit
008836066f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,14 +43,10 @@ import org.springframework.util.StringUtils;
|
||||
public class RedisClusterConfiguration {
|
||||
|
||||
private static final String REDIS_CLUSTER_NODES_CONFIG_PROPERTY = "spring.redis.cluster.nodes";
|
||||
private static final String REDIS_CLUSTER_TIMEOUT_CONFIG_PROPERTY = "spring.redis.cluster.timeout";
|
||||
private static final String REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY = "spring.redis.cluster.max-redirects";
|
||||
private static final String REDIS_CLUSTER_PASSWORD_PROPERTY = "spring.redis.cluster.password";
|
||||
|
||||
private Set<RedisNode> clusterNodes;
|
||||
private Long clusterTimeout;
|
||||
private Integer maxRedirects;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Creates new {@link RedisClusterConfiguration}.
|
||||
@@ -100,17 +96,10 @@ public class RedisClusterConfiguration {
|
||||
appendClusterNodes(commaDelimitedListToSet(propertySource.getProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY)
|
||||
.toString()));
|
||||
}
|
||||
if (propertySource.containsProperty(REDIS_CLUSTER_TIMEOUT_CONFIG_PROPERTY)) {
|
||||
this.clusterTimeout = NumberUtils.parseNumber(propertySource.getProperty(REDIS_CLUSTER_TIMEOUT_CONFIG_PROPERTY)
|
||||
.toString(), Long.class);
|
||||
}
|
||||
if (propertySource.containsProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY)) {
|
||||
this.maxRedirects = NumberUtils.parseNumber(
|
||||
propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class);
|
||||
}
|
||||
if (propertySource.containsProperty(REDIS_CLUSTER_PASSWORD_PROPERTY)) {
|
||||
this.password = propertySource.getProperty(REDIS_CLUSTER_PASSWORD_PROPERTY).toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,25 +142,11 @@ public class RedisClusterConfiguration {
|
||||
* @return
|
||||
*/
|
||||
public RedisClusterConfiguration clusterNode(RedisNode node) {
|
||||
|
||||
this.clusterNodes.add(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Long getClusterTimeout() {
|
||||
return clusterTimeout != null && clusterTimeout > Long.MIN_VALUE ? clusterTimeout : null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param clusterTimeout
|
||||
*/
|
||||
public void setClusterTimeout(long clusterTimeout) {
|
||||
this.clusterTimeout = clusterTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@@ -180,29 +155,14 @@ public class RedisClusterConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param maxRedirects
|
||||
*/
|
||||
public void setMaxRedirects(int maxRedirects) {
|
||||
|
||||
Assert.isTrue(maxRedirects >= 0, "MaxRedirects must be greater or equal to 0");
|
||||
this.maxRedirects = maxRedirects;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param password can be {@literal null} or empty.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param host
|
||||
* @param port
|
||||
@@ -235,21 +195,17 @@ public class RedisClusterConfiguration {
|
||||
* @param password can be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts, long timeout, int redirects, String password) {
|
||||
private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts, long timeout, int redirects,
|
||||
String password) {
|
||||
|
||||
notNull(clusterHostAndPorts, "ClusterHostAndPorts must not be null!");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(REDIS_CLUSTER_NODES_CONFIG_PROPERTY, StringUtils.collectionToCommaDelimitedString(clusterHostAndPorts));
|
||||
if (timeout >= 0) {
|
||||
map.put(REDIS_CLUSTER_TIMEOUT_CONFIG_PROPERTY, Long.valueOf(timeout));
|
||||
}
|
||||
|
||||
if (redirects >= 0) {
|
||||
map.put(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY, Integer.valueOf(redirects));
|
||||
}
|
||||
if (StringUtils.hasText(password)) {
|
||||
map.put(REDIS_CLUSTER_PASSWORD_PROPERTY, password);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -293,11 +293,10 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
hostAndPort.add(new HostAndPort(node.getHost(), node.getPort()));
|
||||
}
|
||||
|
||||
int timeout = clusterConfig.getClusterTimeout() != null ? clusterConfig.getClusterTimeout().intValue() : this.timeout;
|
||||
int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5;
|
||||
|
||||
if (StringUtils.hasText(clusterConfig.getPassword())) {
|
||||
throw new UnsupportedOperationException("Jedis does not support password protected Redis Cluster configurations");
|
||||
|
||||
if (StringUtils.hasText(getPassword())) {
|
||||
throw new IllegalArgumentException("Jedis does not support password protected Redis Cluster configurations!");
|
||||
}
|
||||
|
||||
if (poolConfig != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,6 +40,7 @@ import org.springframework.data.redis.connection.RedisNode;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.lambdaworks.redis.AbstractRedisClient;
|
||||
import com.lambdaworks.redis.LettuceFutures;
|
||||
@@ -49,7 +50,6 @@ import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.RedisFuture;
|
||||
import com.lambdaworks.redis.RedisURI;
|
||||
import com.lambdaworks.redis.cluster.RedisClusterClient;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Connection factory creating <a href="http://github.com/mp911de/lettuce">Lettuce</a>-based connections.
|
||||
@@ -465,12 +465,10 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
|
||||
|
||||
List<RedisURI> initialUris = new ArrayList<RedisURI>();
|
||||
for (RedisNode node : this.clusterConfiguration.getClusterNodes()) {
|
||||
long timeout = this.clusterConfiguration.getClusterTimeout() != null ? this.clusterConfiguration.getClusterTimeout() : this.timeout;
|
||||
|
||||
RedisURI redisURI = new RedisURI(node.getHost(), node.getPort(), timeout, TimeUnit.MILLISECONDS);
|
||||
|
||||
if(StringUtils.hasText(this.clusterConfiguration.getPassword())){
|
||||
redisURI.setPassword(this.clusterConfiguration.getPassword());
|
||||
}else if(StringUtils.hasText(password)){
|
||||
if (StringUtils.hasText(password)) {
|
||||
redisURI.setPassword(password);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user