3232import org .springframework .util .StringUtils ;
3333
3434/**
35- * Configuration class used to set up a {@link RedisConnection} with {@link RedisConnectionFactory} for connecting
36- * to <a href="https://redis.io/topics/sentinel">Redis Sentinel(s)</a>. Useful when setting up a highly available Redis
37- * environment.
35+ * {@link RedisConfiguration Configuration} class used to set up a {@link RedisConnection}
36+ * with {@link RedisConnectionFactory} for connecting to <a href="https://redis.io/topics/sentinel">Redis Sentinel(s)</a>.
37+ * Useful when setting up a highly available Redis environment.
3838 *
3939 * @author Christoph Strobl
4040 * @author Thomas Darimont
@@ -104,20 +104,23 @@ public RedisSentinelConfiguration(PropertySource<?> propertySource) {
104104 this .sentinels = new LinkedHashSet <>();
105105
106106 if (propertySource .containsProperty (REDIS_SENTINEL_MASTER_CONFIG_PROPERTY )) {
107- this .setMaster (propertySource .getProperty (REDIS_SENTINEL_MASTER_CONFIG_PROPERTY ).toString ());
107+ String sentinelMaster = String .valueOf (propertySource .getProperty (REDIS_SENTINEL_MASTER_CONFIG_PROPERTY ));
108+ this .setMaster (sentinelMaster );
108109 }
109110
110111 if (propertySource .containsProperty (REDIS_SENTINEL_NODES_CONFIG_PROPERTY )) {
111- appendSentinels (
112- commaDelimitedListToSet (propertySource . getProperty ( REDIS_SENTINEL_NODES_CONFIG_PROPERTY ). toString () ));
112+ String sentinelNodes = String . valueOf ( propertySource . getProperty ( REDIS_SENTINEL_NODES_CONFIG_PROPERTY ));
113+ appendSentinels ( commaDelimitedListToSet (sentinelNodes ));
113114 }
114115
115116 if (propertySource .containsProperty (REDIS_SENTINEL_PASSWORD_CONFIG_PROPERTY )) {
116- this .setSentinelPassword (propertySource .getProperty (REDIS_SENTINEL_PASSWORD_CONFIG_PROPERTY ).toString ());
117+ String sentinelPassword = String .valueOf (propertySource .getProperty (REDIS_SENTINEL_PASSWORD_CONFIG_PROPERTY ));
118+ this .setSentinelPassword (sentinelPassword );
117119 }
118120
119121 if (propertySource .containsProperty (REDIS_SENTINEL_USERNAME_CONFIG_PROPERTY )) {
120- this .setSentinelUsername (propertySource .getProperty (REDIS_SENTINEL_USERNAME_CONFIG_PROPERTY ).toString ());
122+ String sentinelUsername = String .valueOf (propertySource .getProperty (REDIS_SENTINEL_USERNAME_CONFIG_PROPERTY ));
123+ this .setSentinelUsername (sentinelUsername );
121124 }
122125 }
123126
@@ -128,7 +131,7 @@ public RedisSentinelConfiguration(PropertySource<?> propertySource) {
128131 */
129132 public void setSentinels (Iterable <RedisNode > sentinels ) {
130133
131- Assert .notNull (sentinels , "Cannot set sentinels to ' null' " );
134+ Assert .notNull (sentinels , "Cannot set sentinels to null" );
132135
133136 this .sentinels .clear ();
134137
@@ -148,16 +151,19 @@ public Set<RedisNode> getSentinels() {
148151 */
149152 public void addSentinel (RedisNode sentinel ) {
150153
151- Assert .notNull (sentinel , "Sentinel must not be 'null'" );
154+ Assert .notNull (sentinel , "Sentinel must not be null" );
155+
152156 this .sentinels .add (sentinel );
153157 }
154158
155159 public void setMaster (NamedNode master ) {
156160
157- Assert .notNull (master , "Sentinel master node must not be 'null'" );
161+ Assert .notNull (master , "Sentinel master node must not be null" );
162+
158163 this .master = master ;
159164 }
160165
166+ @ Nullable
161167 public NamedNode getMaster () {
162168 return master ;
163169 }
@@ -217,7 +223,7 @@ public int getDatabase() {
217223 @ Override
218224 public void setDatabase (int index ) {
219225
220- Assert .isTrue (index >= 0 , () -> String .format ("Invalid DB index '%s' (a positive index required) " , index ));
226+ Assert .isTrue (index >= 0 , () -> String .format ("Invalid DB index '%d'; non-negative index required" , index ));
221227
222228 this .database = index ;
223229 }
@@ -270,44 +276,37 @@ public RedisPassword getSentinelPassword() {
270276 }
271277
272278 @ Override
273- public boolean equals (@ Nullable Object o ) {
274- if (this == o ) {
279+ public boolean equals (@ Nullable Object obj ) {
280+
281+ if (this == obj ) {
275282 return true ;
276283 }
277- if (!(o instanceof RedisSentinelConfiguration )) {
278- return false ;
279- }
280- RedisSentinelConfiguration that = (RedisSentinelConfiguration ) o ;
281- if (database != that .database ) {
282- return false ;
283- }
284- if (!ObjectUtils .nullSafeEquals (master , that .master )) {
285- return false ;
286- }
287- if (!ObjectUtils .nullSafeEquals (sentinels , that .sentinels )) {
288- return false ;
289- }
290- if (!ObjectUtils .nullSafeEquals (dataNodeUsername , that .dataNodeUsername )) {
291- return false ;
292- }
293- if (!ObjectUtils .nullSafeEquals (dataNodePassword , that .dataNodePassword )) {
294- return false ;
295- }
296- if (!ObjectUtils .nullSafeEquals (sentinelUsername , that .sentinelUsername )) {
284+
285+ if (!(obj instanceof RedisSentinelConfiguration that )) {
297286 return false ;
298287 }
299- return ObjectUtils .nullSafeEquals (sentinelPassword , that .sentinelPassword );
288+
289+ return this .database == that .database
290+ && ObjectUtils .nullSafeEquals (this .master , that .master )
291+ && ObjectUtils .nullSafeEquals (this .sentinels , that .sentinels )
292+ && ObjectUtils .nullSafeEquals (this .dataNodeUsername , that .dataNodeUsername )
293+ && ObjectUtils .nullSafeEquals (this .dataNodePassword , that .dataNodePassword )
294+ && ObjectUtils .nullSafeEquals (this .sentinelUsername , that .sentinelUsername )
295+ && ObjectUtils .nullSafeEquals (this .sentinelPassword , that .sentinelPassword );
300296 }
301297
302298 @ Override
303299 public int hashCode () {
300+
304301 int result = ObjectUtils .nullSafeHashCode (master );
302+
305303 result = 31 * result + ObjectUtils .nullSafeHashCode (sentinels );
306304 result = 31 * result + database ;
307305 result = 31 * result + ObjectUtils .nullSafeHashCode (dataNodeUsername );
308306 result = 31 * result + ObjectUtils .nullSafeHashCode (dataNodePassword );
309307 result = 31 * result + ObjectUtils .nullSafeHashCode (sentinelUsername );
310308 result = 31 * result + ObjectUtils .nullSafeHashCode (sentinelPassword );
309+
311310 return result ;
312311 }
313312
@@ -323,6 +322,7 @@ private static Map<String, Object> asMap(String master, Set<String> sentinelHost
323322 Assert .noNullElements (sentinelHostAndPorts , "ClusterHostAndPorts must not contain null elements" );
324323
325324 Map <String , Object > map = new HashMap <>();
325+
326326 map .put (REDIS_SENTINEL_MASTER_CONFIG_PROPERTY , master );
327327 map .put (REDIS_SENTINEL_NODES_CONFIG_PROPERTY , StringUtils .collectionToCommaDelimitedString (sentinelHostAndPorts ));
328328
0 commit comments