20
20
import io .lettuce .core .TimeoutOptions ;
21
21
import io .lettuce .core .resource .ClientResources ;
22
22
import org .springframework .beans .factory .annotation .Value ;
23
- import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
24
- import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
25
23
import org .springframework .context .annotation .Bean ;
26
24
import org .springframework .context .annotation .Configuration ;
27
25
import org .springframework .context .annotation .Import ;
@@ -60,7 +58,7 @@ public class RedisBasicConfig {
60
58
@ Value ("${spring.data.redis.port:6379}" )
61
59
int port ;
62
60
63
- @ Value ("${spring.data.redis.cluster.nodes:@null }" )
61
+ @ Value ("${spring.data.redis.cluster.nodes}" )
64
62
List <String > clusterNodes ;
65
63
@ Value ("${spring.data.redis.lettuce.client.io-thread-pool-size:8}" )
66
64
int lettuceIOThreadPoolSize ;
@@ -86,22 +84,17 @@ ReactiveRedisTemplate<String, String> reactiveRedisTemplate(ReactiveRedisConnect
86
84
}
87
85
88
86
@ Bean
89
- @ ConditionalOnProperty ( "spring.redis.cluster.nodes" )
90
- RedisConfiguration redisClusterConfiguration ( ) {
91
- Assert .notNull ( clusterNodes , "clusterNodes are required for redis-cluster mode" );
87
+ RedisConfiguration redisConfiguration () {
88
+ if ( clusterNodes == null || clusterNodes . isEmpty () ) {
89
+ Assert .hasText ( host , "host is required for redis-standalone mode" );
92
90
93
- final RedisClusterConfiguration config = new RedisClusterConfiguration (clusterNodes );
94
- config .setUsername (username );
95
- config .setPassword (password );
96
- return config ;
97
- }
98
-
99
- @ Bean
100
- @ ConditionalOnMissingBean (RedisConfiguration .class )
101
- RedisConfiguration redisStandaloneConfiguration () {
102
- Assert .hasText (host , "host is required for redis-standalone mode" );
91
+ final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration (host , port );
92
+ config .setUsername (username );
93
+ config .setPassword (password );
94
+ return config ;
95
+ }
103
96
104
- final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration ( host , port );
97
+ final RedisClusterConfiguration config = new RedisClusterConfiguration ( clusterNodes );
105
98
config .setUsername (username );
106
99
config .setPassword (password );
107
100
return config ;
0 commit comments