@@ -319,7 +319,7 @@ protected JedisConnection postProcessConnection(JedisConnection connection) {
319
319
*/
320
320
public void afterPropertiesSet () {
321
321
322
- clientConfig = createClientConfig (getRedisUsername (), getRedisPassword ());
322
+ clientConfig = createClientConfig (getDatabase (), getRedisUsername (), getRedisPassword ());
323
323
324
324
if (shardInfo == null && clientConfiguration instanceof MutableJedisClientConfiguration ) {
325
325
@@ -360,15 +360,19 @@ public void afterPropertiesSet() {
360
360
this .initialized = true ;
361
361
}
362
362
363
- private JedisClientConfig createClientConfig (@ Nullable String username , RedisPassword password ) {
363
+ private JedisClientConfig createSentinelClientConfig (SentinelConfiguration sentinelConfiguration ) {
364
+ return createClientConfig (0 , null , sentinelConfiguration .getSentinelPassword ());
365
+ }
366
+
367
+ private JedisClientConfig createClientConfig (int database , @ Nullable String username , RedisPassword password ) {
364
368
365
369
DefaultJedisClientConfig .Builder builder = DefaultJedisClientConfig .builder ();
366
370
367
371
clientConfiguration .getClientName ().ifPresent (builder ::clientName );
368
372
builder .connectionTimeoutMillis (getConnectTimeout ());
369
373
builder .socketTimeoutMillis (getReadTimeout ());
370
374
371
- builder .database (getDatabase () );
375
+ builder .database (database );
372
376
373
377
if (!ObjectUtils .isEmpty (username )) {
374
378
builder .user (username );
@@ -405,9 +409,8 @@ private Pool<Jedis> createPool() {
405
409
protected Pool <Jedis > createRedisSentinelPool (RedisSentinelConfiguration config ) {
406
410
407
411
GenericObjectPoolConfig <Jedis > poolConfig = getPoolConfig () != null ? getPoolConfig () : new JedisPoolConfig ();
408
- String sentinelUser = null ;
409
412
410
- JedisClientConfig sentinelConfig = createClientConfig ( sentinelUser , config . getSentinelPassword () );
413
+ JedisClientConfig sentinelConfig = createSentinelClientConfig ( config );
411
414
return new JedisSentinelPool (config .getMaster ().getName (), convertToJedisSentinelSet (config .getSentinels ()),
412
415
poolConfig , this .clientConfig , sentinelConfig );
413
416
}
@@ -513,7 +516,7 @@ public RedisConnection getConnection() {
513
516
514
517
SentinelConfiguration sentinelConfiguration = getSentinelConfiguration ();
515
518
if (sentinelConfiguration != null ) {
516
- sentinelConfig = createClientConfig ( null , sentinelConfiguration . getSentinelPassword () );
519
+ sentinelConfig = createSentinelClientConfig ( sentinelConfiguration );
517
520
}
518
521
519
522
JedisConnection connection = (getUsePool () ? new JedisConnection (jedis , pool , this .clientConfig , sentinelConfig )
@@ -904,7 +907,7 @@ private Jedis getActiveSentinel() {
904
907
Assert .isTrue (RedisConfiguration .isSentinelConfiguration (configuration ), "SentinelConfig must not be null!" );
905
908
SentinelConfiguration sentinelConfiguration = (SentinelConfiguration ) configuration ;
906
909
907
- JedisClientConfig clientConfig = createClientConfig ( null , sentinelConfiguration . getSentinelPassword () );
910
+ JedisClientConfig clientConfig = createSentinelClientConfig ( sentinelConfiguration );
908
911
for (RedisNode node : sentinelConfiguration .getSentinels ()) {
909
912
910
913
Jedis jedis = null ;
@@ -929,6 +932,7 @@ private Jedis getActiveSentinel() {
929
932
throw new InvalidDataAccessResourceUsageException ("No Sentinel found" );
930
933
}
931
934
935
+
932
936
private static Set <HostAndPort > convertToJedisSentinelSet (Collection <RedisNode > nodes ) {
933
937
934
938
if (CollectionUtils .isEmpty (nodes )) {
0 commit comments