Skip to content

Commit 53a9757

Browse files
committed
Add Jedis maxTotalRetriesDuration in config.
1 parent eaef5da commit 53a9757

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ public class RedisClusterConfiguration implements RedisConfiguration, ClusterCon
4646

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

5051
private Set<RedisNode> clusterNodes;
5152
private @Nullable Integer maxRedirects;
5253
private @Nullable String username = null;
54+
private @Nullable Integer maxTotalRetriesTime;
5355
private RedisPassword password = RedisPassword.none();
5456

5557
/**
@@ -101,6 +103,10 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
101103
this.maxRedirects = NumberUtils.parseNumber(
102104
propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class);
103105
}
106+
if (propertySource.containsProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME)) {
107+
this.maxTotalRetriesTime = NumberUtils.parseNumber(
108+
propertySource.getProperty(REDIS_CLUSTER_MAX_TOTAL_RETRIES_TIME).toString(), Integer.class);
109+
}
104110
}
105111

106112
/**
@@ -158,6 +164,18 @@ public void setMaxRedirects(int maxRedirects) {
158164
this.maxRedirects = maxRedirects;
159165
}
160166

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,12 @@ interface ClusterConfiguration extends WithPassword {
477477
/**
478478
* @return max number of redirects to follow or {@literal null} if not set.
479479
*/
480-
@Nullable
481-
Integer getMaxRedirects();
480+
@Nullable Integer getMaxRedirects();
481+
482+
/**
483+
* @return max total retries time in millis {@literal null} if not set.
484+
*/
485+
@Nullable Integer getMaxTotalRetriesTime();
482486
}
483487

484488
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig,
410410

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

413+
if (clusterConfig.getMaxTotalRetriesTime() != null) {
414+
return new JedisCluster(hostAndPort, this.clientConfig, redirects,
415+
Duration.ofMillis(clusterConfig.getMaxTotalRetriesTime()), poolConfig);
416+
}
413417
return new JedisCluster(hostAndPort, this.clientConfig, redirects, poolConfig);
414418
}
415419

0 commit comments

Comments
 (0)