Add option to disable Redis Cluster dynamic sources refresh
This commit adds an option to enable/disable the DynamicRefreshSources setting on the Lettuce cluster toplogy refresh options. See gh-22571
This commit is contained in:
@@ -138,6 +138,9 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
if (refreshProperties.isAdaptive()) {
|
||||
refreshBuilder.enableAllAdaptiveRefreshTriggers();
|
||||
}
|
||||
if (refreshProperties.isDynamicSources() != null) {
|
||||
refreshBuilder.dynamicRefreshSources(refreshProperties.isDynamicSources());
|
||||
}
|
||||
return builder.topologyRefreshOptions(refreshBuilder.build());
|
||||
}
|
||||
return ClientOptions.builder();
|
||||
|
||||
@@ -410,6 +410,13 @@ public class RedisProperties {
|
||||
*/
|
||||
private boolean adaptive;
|
||||
|
||||
/**
|
||||
* Whether discovered nodes should be used as the source for the cluster
|
||||
* topology. When set to false, only the initial seed nodes
|
||||
* will be used as sources for topology discovery.
|
||||
*/
|
||||
private Boolean dynamicSources;
|
||||
|
||||
public Duration getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
@@ -426,6 +433,14 @@ public class RedisProperties {
|
||||
this.adaptive = adaptive;
|
||||
}
|
||||
|
||||
public Boolean isDynamicSources() {
|
||||
return this.dynamicSources;
|
||||
}
|
||||
|
||||
public void setDynamicSources(Boolean dynamicSources) {
|
||||
this.dynamicSources = dynamicSources;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import io.lettuce.core.ClientOptions;
|
||||
import io.lettuce.core.cluster.ClusterClientOptions;
|
||||
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
|
||||
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions.RefreshTrigger;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -312,6 +313,36 @@ class RedisAutoConfigurationTests {
|
||||
ClientOptions.class, (options) -> assertThat(options.getClass()).isEqualTo(ClientOptions.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClusterDynamicSourcesEnabled() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-sources=true")
|
||||
.run(assertClientOptions(ClusterClientOptions.class,
|
||||
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
|
||||
.isTrue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClusterDynamicSourcesDisabled() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-sources=false")
|
||||
.run(assertClientOptions(ClusterClientOptions.class,
|
||||
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
|
||||
.isFalse()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClusterDynamicSourcesUnspecifiedUsesDefault() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-sources=")
|
||||
.run(assertClientOptions(ClusterClientOptions.class,
|
||||
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
|
||||
.isEqualTo(ClusterTopologyRefreshOptions.DEFAULT_DYNAMIC_REFRESH_SOURCES)));
|
||||
}
|
||||
|
||||
private <T extends ClientOptions> ContextConsumer<AssertableApplicationContext> assertClientOptions(
|
||||
Class<T> expectedType, Consumer<T> options) {
|
||||
return (context) -> {
|
||||
|
||||
Reference in New Issue
Block a user