1515 */
1616package org .springframework .data .redis .connection ;
1717
18- import static org .springframework .util .StringUtils .* ;
18+ import static org .springframework .util .StringUtils .commaDelimitedListToSet ;
1919
2020import java .util .Collection ;
2121import java .util .Collections ;
2727import org .springframework .core .env .MapPropertySource ;
2828import org .springframework .core .env .PropertySource ;
2929import org .springframework .data .redis .connection .RedisConfiguration .ClusterConfiguration ;
30+ import org .springframework .data .redis .util .RedisAssertions ;
3031import org .springframework .lang .Nullable ;
3132import org .springframework .util .Assert ;
3233import org .springframework .util .NumberUtils ;
@@ -47,11 +48,14 @@ public class RedisClusterConfiguration implements RedisConfiguration, ClusterCon
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" ;
4950
50- private Set <RedisNode > clusterNodes ;
5151 private @ Nullable Integer maxRedirects ;
52- private @ Nullable String username = null ;
52+
5353 private RedisPassword password = RedisPassword .none ();
5454
55+ private final Set <RedisNode > clusterNodes ;
56+
57+ private @ Nullable String username = null ;
58+
5559 /**
5660 * Creates new {@link RedisClusterConfiguration}.
5761 */
@@ -94,12 +98,12 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
9498 this .clusterNodes = new LinkedHashSet <>();
9599
96100 if (propertySource .containsProperty (REDIS_CLUSTER_NODES_CONFIG_PROPERTY )) {
97- appendClusterNodes (
98- commaDelimitedListToSet (propertySource . getProperty ( REDIS_CLUSTER_NODES_CONFIG_PROPERTY ). toString ( )));
101+ Object redisClusterNodes = propertySource . getProperty ( REDIS_CLUSTER_NODES_CONFIG_PROPERTY );
102+ appendClusterNodes ( commaDelimitedListToSet (String . valueOf ( redisClusterNodes )));
99103 }
100104 if (propertySource .containsProperty (REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY )) {
101- this . maxRedirects = NumberUtils . parseNumber (
102- propertySource . getProperty ( REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY ). toString ( ), Integer .class );
105+ Object clusterMaxRedirects = propertySource . getProperty ( REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY );
106+ this . maxRedirects = NumberUtils . parseNumber ( String . valueOf ( clusterMaxRedirects ), Integer .class );
103107 }
104108 }
105109
@@ -110,7 +114,7 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
110114 */
111115 public void setClusterNodes (Iterable <RedisNode > nodes ) {
112116
113- Assert .notNull (nodes , "Cannot set cluster nodes to ' null' " );
117+ Assert .notNull (nodes , "Cannot set cluster nodes to null" );
114118
115119 this .clusterNodes .clear ();
116120
@@ -130,9 +134,7 @@ public Set<RedisNode> getClusterNodes() {
130134 * @param node must not be {@literal null}.
131135 */
132136 public void addClusterNode (RedisNode node ) {
133-
134- Assert .notNull (node , "ClusterNode must not be 'null'" );
135- this .clusterNodes .add (node );
137+ this .clusterNodes .add (RedisAssertions .requireNonNull (node , "ClusterNode must not be null" ));
136138 }
137139
138140 /**
@@ -141,6 +143,7 @@ public void addClusterNode(RedisNode node) {
141143 public RedisClusterConfiguration clusterNode (RedisNode node ) {
142144
143145 this .clusterNodes .add (node );
146+
144147 return this ;
145148 }
146149
@@ -155,6 +158,7 @@ public Integer getMaxRedirects() {
155158 public void setMaxRedirects (int maxRedirects ) {
156159
157160 Assert .isTrue (maxRedirects >= 0 , "MaxRedirects must be greater or equal to 0" );
161+
158162 this .maxRedirects = maxRedirects ;
159163 }
160164
@@ -192,31 +196,24 @@ public RedisPassword getPassword() {
192196
193197 @ Override
194198 public void setPassword (RedisPassword password ) {
195-
196- Assert .notNull (password , "RedisPassword must not be null" );
197-
198- this .password = password ;
199+ this .password = RedisAssertions .requireNonNull (password , "RedisPassword must not be null" );
199200 }
200201
201202 @ Override
202- public boolean equals (@ Nullable Object o ) {
203- if (this == o ) {
203+ public boolean equals (@ Nullable Object obj ) {
204+
205+ if (this == obj ) {
204206 return true ;
205207 }
206- if (!(o instanceof RedisClusterConfiguration )) {
207- return false ;
208- }
209- RedisClusterConfiguration that = (RedisClusterConfiguration ) o ;
210- if (!ObjectUtils .nullSafeEquals (clusterNodes , that .clusterNodes )) {
211- return false ;
212- }
213- if (!ObjectUtils .nullSafeEquals (maxRedirects , that .maxRedirects )) {
214- return false ;
215- }
216- if (!ObjectUtils .nullSafeEquals (username , that .username )) {
208+
209+ if (!(obj instanceof RedisClusterConfiguration that )) {
217210 return false ;
218211 }
219- return ObjectUtils .nullSafeEquals (password , that .password );
212+
213+ return ObjectUtils .nullSafeEquals (this .clusterNodes , that .clusterNodes )
214+ && ObjectUtils .nullSafeEquals (this .maxRedirects , that .maxRedirects )
215+ && ObjectUtils .nullSafeEquals (this .username , that .username )
216+ && ObjectUtils .nullSafeEquals (this .password , that .password );
220217 }
221218
222219 @ Override
@@ -239,6 +236,7 @@ private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts,
239236 Assert .noNullElements (clusterHostAndPorts , "ClusterHostAndPorts must not contain null elements" );
240237
241238 Map <String , Object > map = new HashMap <>();
239+
242240 map .put (REDIS_CLUSTER_NODES_CONFIG_PROPERTY , StringUtils .collectionToCommaDelimitedString (clusterHostAndPorts ));
243241
244242 if (redirects >= 0 ) {
@@ -247,5 +245,4 @@ private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts,
247245
248246 return map ;
249247 }
250-
251248}
0 commit comments