Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Tsung-en Hsiao
* @since 1.7
*/
public class RedisClusterConfiguration implements RedisConfiguration, ClusterConfiguration {

private static final String REDIS_CLUSTER_NODES_CONFIG_PROPERTY = "spring.redis.cluster.nodes";
private static final String REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY = "spring.redis.cluster.max-redirects";
private static final String REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME = "spring.redis.cluster.max-total-retries-time";

private Set<RedisNode> clusterNodes;
private @Nullable Integer maxRedirects;
private @Nullable String username = null;
private @Nullable Integer maxTotalRetriesTime;
private RedisPassword password = RedisPassword.none();

/**
Expand Down Expand Up @@ -101,6 +104,10 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
this.maxRedirects = NumberUtils.parseNumber(
propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class);
}
if (propertySource.containsProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME)) {
this.maxTotalRetriesTime = NumberUtils.parseNumber(
propertySource.getProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME).toString(), Integer.class);
}
}

/**
Expand Down Expand Up @@ -158,6 +165,18 @@ public void setMaxRedirects(int maxRedirects) {
this.maxRedirects = maxRedirects;
}

@Override public Integer getMaxTotalRetriesTime() {
return maxTotalRetriesTime;
}

/**
* @param maxTotalRetriesTime the max total retries time in millisecond(s)
* only applicable to Jedis cluster connection.
*/
public void setMaxTotalRetriesTime(Integer maxTotalRetriesTime) {
this.maxTotalRetriesTime = maxTotalRetriesTime;
}

/**
* @param host Redis cluster node host name or ip address.
* @param port Redis cluster node port.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @author Christoph Strobl
* @author Luis De Bello
* @author Vikas Garg
* @author Tsung-en Hsiao
* @since 2.1
*/
public interface RedisConfiguration {
Expand Down Expand Up @@ -477,8 +478,12 @@ interface ClusterConfiguration extends WithPassword {
/**
* @return max number of redirects to follow or {@literal null} if not set.
*/
@Nullable
Integer getMaxRedirects();
@Nullable Integer getMaxRedirects();

/**
* @return max total retries time in millis {@literal null} if not set.
*/
@Nullable Integer getMaxTotalRetriesTime();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
* @author Mark Paluch
* @author Fu Jian
* @author Ajith Kumar
* @author Tsung-en Hsiao
* @see JedisClientConfiguration
* @see Jedis
*/
Expand Down Expand Up @@ -410,6 +411,10 @@ protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig,

int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects() : 5;

if (clusterConfig.getMaxTotalRetriesTime() != null) {
return new JedisCluster(hostAndPort, this.clientConfig, redirects,
Duration.ofMillis(clusterConfig.getMaxTotalRetriesTime()), poolConfig);
}
return new JedisCluster(hostAndPort, this.clientConfig, redirects, poolConfig);
}

Expand Down