@@ -319,7 +319,7 @@ protected JedisConnection postProcessConnection(JedisConnection connection) {
319319 */
320320 public void afterPropertiesSet () {
321321
322- clientConfig = createClientConfig (getRedisUsername (), getRedisPassword ());
322+ clientConfig = createClientConfig (getDatabase (), getRedisUsername (), getRedisPassword ());
323323
324324 if (shardInfo == null && clientConfiguration instanceof MutableJedisClientConfiguration ) {
325325
@@ -360,15 +360,19 @@ public void afterPropertiesSet() {
360360 this .initialized = true ;
361361 }
362362
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 ) {
364368
365369 DefaultJedisClientConfig .Builder builder = DefaultJedisClientConfig .builder ();
366370
367371 clientConfiguration .getClientName ().ifPresent (builder ::clientName );
368372 builder .connectionTimeoutMillis (getConnectTimeout ());
369373 builder .socketTimeoutMillis (getReadTimeout ());
370374
371- builder .database (getDatabase () );
375+ builder .database (database );
372376
373377 if (!ObjectUtils .isEmpty (username )) {
374378 builder .user (username );
@@ -405,9 +409,8 @@ private Pool<Jedis> createPool() {
405409 protected Pool <Jedis > createRedisSentinelPool (RedisSentinelConfiguration config ) {
406410
407411 GenericObjectPoolConfig <Jedis > poolConfig = getPoolConfig () != null ? getPoolConfig () : new JedisPoolConfig ();
408- String sentinelUser = null ;
409412
410- JedisClientConfig sentinelConfig = createClientConfig ( sentinelUser , config . getSentinelPassword () );
413+ JedisClientConfig sentinelConfig = createSentinelClientConfig ( config );
411414 return new JedisSentinelPool (config .getMaster ().getName (), convertToJedisSentinelSet (config .getSentinels ()),
412415 poolConfig , this .clientConfig , sentinelConfig );
413416 }
@@ -513,7 +516,7 @@ public RedisConnection getConnection() {
513516
514517 SentinelConfiguration sentinelConfiguration = getSentinelConfiguration ();
515518 if (sentinelConfiguration != null ) {
516- sentinelConfig = createClientConfig ( null , sentinelConfiguration . getSentinelPassword () );
519+ sentinelConfig = createSentinelClientConfig ( sentinelConfiguration );
517520 }
518521
519522 JedisConnection connection = (getUsePool () ? new JedisConnection (jedis , pool , this .clientConfig , sentinelConfig )
@@ -904,7 +907,7 @@ private Jedis getActiveSentinel() {
904907 Assert .isTrue (RedisConfiguration .isSentinelConfiguration (configuration ), "SentinelConfig must not be null!" );
905908 SentinelConfiguration sentinelConfiguration = (SentinelConfiguration ) configuration ;
906909
907- JedisClientConfig clientConfig = createClientConfig ( null , sentinelConfiguration . getSentinelPassword () );
910+ JedisClientConfig clientConfig = createSentinelClientConfig ( sentinelConfiguration );
908911 for (RedisNode node : sentinelConfiguration .getSentinels ()) {
909912
910913 Jedis jedis = null ;
@@ -929,6 +932,7 @@ private Jedis getActiveSentinel() {
929932 throw new InvalidDataAccessResourceUsageException ("No Sentinel found" );
930933 }
931934
935+
932936 private static Set <HostAndPort > convertToJedisSentinelSet (Collection <RedisNode > nodes ) {
933937
934938 if (CollectionUtils .isEmpty (nodes )) {
0 commit comments