Skip to content

Commit 3ab0d67

Browse files
committed
Polish "Add support for static master-replica with Lettuce"
See spring-projectsgh-46957
1 parent 5def410 commit 3ab0d67

File tree

5 files changed

+8
-21
lines changed

5 files changed

+8
-21
lines changed

module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/JedisConnectionConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ private JedisConnectionFactory createJedisConnectionFactory(
103103
Assert.state(sentinelConfig != null, "'sentinelConfig' must not be null");
104104
yield new JedisConnectionFactory(sentinelConfig, clientConfiguration);
105105
}
106-
case STATIC_MASTER_REPLICA -> throw new IllegalStateException("Static master replica is not supported for Jedis");
107106
};
108107
}
109108

module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/LettuceConnectionConfiguration.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4141
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
4242
import org.springframework.boot.data.redis.autoconfigure.RedisConnectionDetails.Node;
43-
import org.springframework.boot.data.redis.autoconfigure.RedisProperties.Lettuce;
4443
import org.springframework.boot.data.redis.autoconfigure.RedisProperties.Lettuce.Cluster.Refresh;
4544
import org.springframework.boot.data.redis.autoconfigure.RedisProperties.Pool;
4645
import org.springframework.boot.ssl.SslBundle;
@@ -145,17 +144,11 @@ private LettuceConnectionFactory createConnectionFactory(
145144
Assert.state(sentinelConfig != null, "'sentinelConfig' must not be null");
146145
yield new LettuceConnectionFactory(sentinelConfig, clientConfiguration);
147146
}
148-
case STATIC_MASTER_REPLICA -> {
149-
RedisStaticMasterReplicaConfiguration configuration = getStaticMasterReplicaConfiguration();
150-
Assert.state(configuration != null, "'staticMasterReplicaConfiguration' must not be null");
151-
yield new LettuceConnectionFactory(configuration, clientConfiguration);
152-
}
153147
};
154148
}
155149

156150
private @Nullable RedisStaticMasterReplicaConfiguration getStaticMasterReplicaConfiguration() {
157151
RedisProperties.Lettuce lettuce = getProperties().getLettuce();
158-
159152
if (!CollectionUtils.isEmpty(lettuce.getNodes())) {
160153
List<Node> nodes = asNodes(lettuce.getNodes());
161154
RedisStaticMasterReplicaConfiguration configuration = new RedisStaticMasterReplicaConfiguration(
@@ -169,7 +162,6 @@ private LettuceConnectionFactory createConnectionFactory(
169162

170163
return configuration;
171164
}
172-
173165
return null;
174166
}
175167

module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/RedisConnectionConfiguration.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
3636
import org.springframework.util.Assert;
3737
import org.springframework.util.ClassUtils;
38-
import org.springframework.util.CollectionUtils;
3938

4039
/**
4140
* Base Redis connection configuration.
@@ -158,7 +157,8 @@ protected final RedisProperties getProperties() {
158157

159158
protected @Nullable SslBundle getSslBundle() {
160159
return switch (this.mode) {
161-
case STANDALONE, STATIC_MASTER_REPLICA -> (this.connectionDetails.getStandalone() != null)
160+
// FIXME: SSL bundle for static master replica
161+
case STANDALONE -> (this.connectionDetails.getStandalone() != null)
162162
? this.connectionDetails.getStandalone().getSslBundle() : null;
163163
case CLUSTER -> (this.connectionDetails.getCluster() != null)
164164
? this.connectionDetails.getCluster().getSslBundle() : null;
@@ -199,15 +199,12 @@ private Mode determineMode() {
199199
if (getClusterConfiguration() != null) {
200200
return Mode.CLUSTER;
201201
}
202-
if (!CollectionUtils.isEmpty(this.properties.getLettuce().getNodes())) {
203-
return Mode.STATIC_MASTER_REPLICA;
204-
}
205202
return Mode.STANDALONE;
206203
}
207204

208205
enum Mode {
209206

210-
STANDALONE, CLUSTER, SENTINEL, STATIC_MASTER_REPLICA
207+
STANDALONE, CLUSTER, SENTINEL
211208

212209
}
213210

module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/RedisProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ public static class Lettuce {
484484
private final Cluster cluster = new Cluster();
485485

486486
/**
487-
* List of static master-replica "host:port" pairs regardless of role
488-
* as the actual roles are determined by querying each node's ROLE command.
487+
* List of static master-replica "host:port" pairs regardless of role as the
488+
* actual roles are determined by querying each node's ROLE command.
489489
*/
490490
private @Nullable List<String> nodes;
491491

module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/RedisAutoConfigurationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,9 @@ void testRedisConfigurationWithClusterAndAuthentication() {
506506
void testRedisConfigurationWithStaticMasterReplica() {
507507
List<String> staticMasterReplicaNodes = Arrays.asList("127.0.0.1:28319", "127.0.0.1:28320", "[::1]:28321");
508508
this.contextRunner
509-
.withPropertyValues(
510-
"spring.data.redis.lettuce.static-master-replica.nodes[0]:" + staticMasterReplicaNodes.get(0),
511-
"spring.data.redis.lettuce.static-master-replica.nodes[1]:" + staticMasterReplicaNodes.get(1),
512-
"spring.data.redis.lettuce.static-master-replica.nodes[2]:" + staticMasterReplicaNodes.get(2))
509+
.withPropertyValues("spring.data.redis.lettuce.nodes[0]:" + staticMasterReplicaNodes.get(0),
510+
"spring.data.redis.lettuce.nodes[1]:" + staticMasterReplicaNodes.get(1),
511+
"spring.data.redis.lettuce.nodes[2]:" + staticMasterReplicaNodes.get(2))
513512
.run((context) -> {
514513
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
515514
assertThat(connectionFactory.getSentinelConfiguration()).isNull();

0 commit comments

Comments
 (0)