Skip to content

Commit 41f1965

Browse files
committed
Add Jedis maxTotalRetriesDuration in config.
1 parent eaef5da commit 41f1965

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/main/java/org/springframework/data/redis/connection/RedisClusterConfiguration.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@
4040
*
4141
* @author Christoph Strobl
4242
* @author Mark Paluch
43+
* @author Tsung-en Hsiao
4344
* @since 1.7
4445
*/
4546
public class RedisClusterConfiguration implements RedisConfiguration, ClusterConfiguration {
4647

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

5052
private Set<RedisNode> clusterNodes;
5153
private @Nullable Integer maxRedirects;
5254
private @Nullable String username = null;
55+
private @Nullable Integer maxTotalRetriesTime;
5356
private RedisPassword password = RedisPassword.none();
5457

5558
/**
@@ -101,6 +104,10 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
101104
this.maxRedirects = NumberUtils.parseNumber(
102105
propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class);
103106
}
107+
if (propertySource.containsProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME)) {
108+
this.maxTotalRetriesTime = NumberUtils.parseNumber(
109+
propertySource.getProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME).toString(), Integer.class);
110+
}
104111
}
105112

106113
/**
@@ -158,6 +165,18 @@ public void setMaxRedirects(int maxRedirects) {
158165
this.maxRedirects = maxRedirects;
159166
}
160167

168+
@Override public Integer getMaxTotalRetriesTime() {
169+
return maxTotalRetriesTime;
170+
}
171+
172+
/**
173+
* @param maxTotalRetriesTime the max total retries time in millisecond(s)
174+
* only applicable to Jedis cluster connection.
175+
*/
176+
public void setMaxTotalRetriesTime(Integer maxTotalRetriesTime) {
177+
this.maxTotalRetriesTime = maxTotalRetriesTime;
178+
}
179+
161180
/**
162181
* @param host Redis cluster node host name or ip address.
163182
* @param port Redis cluster node port.

src/main/java/org/springframework/data/redis/connection/RedisConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* @author Christoph Strobl
3333
* @author Luis De Bello
3434
* @author Vikas Garg
35+
* @author Tsung-en Hsiao
3536
* @since 2.1
3637
*/
3738
public interface RedisConfiguration {
@@ -477,8 +478,12 @@ interface ClusterConfiguration extends WithPassword {
477478
/**
478479
* @return max number of redirects to follow or {@literal null} if not set.
479480
*/
480-
@Nullable
481-
Integer getMaxRedirects();
481+
@Nullable Integer getMaxRedirects();
482+
483+
/**
484+
* @return max total retries time in millis {@literal null} if not set.
485+
*/
486+
@Nullable Integer getMaxTotalRetriesTime();
482487
}
483488

484489
/**

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
* @author Mark Paluch
8383
* @author Fu Jian
8484
* @author Ajith Kumar
85+
* @author Tsung-en Hsiao
8586
* @see JedisClientConfiguration
8687
* @see Jedis
8788
*/
@@ -410,6 +411,10 @@ protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig,
410411

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

414+
if (clusterConfig.getMaxTotalRetriesTime() != null) {
415+
return new JedisCluster(hostAndPort, this.clientConfig, redirects,
416+
Duration.ofMillis(clusterConfig.getMaxTotalRetriesTime()), poolConfig);
417+
}
413418
return new JedisCluster(hostAndPort, this.clientConfig, redirects, poolConfig);
414419
}
415420

0 commit comments

Comments
 (0)