58
58
import org .springframework .util .Assert ;
59
59
import org .springframework .util .ClassUtils ;
60
60
import org .springframework .util .CollectionUtils ;
61
+ import org .springframework .util .StringUtils ;
61
62
62
63
/**
63
64
* Connection factory creating <a href="https://github.com/xetorthio/jedis">Jedis</a> based connections.
@@ -328,7 +329,10 @@ public void afterPropertiesSet() {
328
329
clientConfiguration .getHostnameVerifier ().orElse (null ));
329
330
330
331
getRedisPassword ().map (String ::new ).ifPresent (shardInfo ::setPassword );
331
- getRedisUsername ().ifPresent (shardInfo ::setUser );
332
+ String username = getRedisUsername ();
333
+ if (StringUtils .hasText (username )) {
334
+ shardInfo .setUser (username );
335
+ }
332
336
333
337
int readTimeout = getReadTimeout ();
334
338
@@ -375,8 +379,8 @@ protected Pool<Jedis> createRedisSentinelPool(RedisSentinelConfiguration config)
375
379
String sentinelPassword = config .getSentinelPassword ().toOptional ().map (String ::new ).orElse (null );
376
380
377
381
return new JedisSentinelPool (config .getMaster ().getName (), convertToJedisSentinelSet (config .getSentinels ()),
378
- poolConfig , getConnectTimeout (), getReadTimeout (), getUsername (), getPassword (), getDatabase (),
379
- getClientName (), getConnectTimeout (), getReadTimeout (), sentinelUser , sentinelPassword , getClientName ());
382
+ poolConfig , getConnectTimeout (), getReadTimeout (), getUsername (), getPassword (), getDatabase (), getClientName (),
383
+ getConnectTimeout (), getReadTimeout (), sentinelUser , sentinelPassword , getClientName ());
380
384
}
381
385
382
386
/**
@@ -556,7 +560,7 @@ public void setUseSsl(boolean useSsl) {
556
560
*/
557
561
@ Nullable
558
562
private String getUsername () {
559
- return getRedisUsername (). orElse ( null ) ;
563
+ return getRedisUsername ();
560
564
}
561
565
562
566
/**
@@ -569,7 +573,8 @@ public String getPassword() {
569
573
return getRedisPassword ().map (String ::new ).orElse (null );
570
574
}
571
575
572
- private Optional <String > getRedisUsername () {
576
+ @ Nullable
577
+ private String getRedisUsername () {
573
578
return RedisConfiguration .getUsernameOrElse (this .configuration , standaloneConfig ::getUsername );
574
579
}
575
580
0 commit comments