Hi team,

it appears that a provided password in the spring.data.redis.url property is not taken into account since Spring Boot 3 (version used 3.1.0), which lets a Redis connection fail.

For example, the password is provided in this spring.data.redis.url property:

spring.data.redis.url=redis://password@redis-host:6379

And when retrieving the password from, for example, a RedisStandaloneConfiguration, the password is empty:

import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class RedisConfig {

    @Bean
    RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory)
                                                      throws IllegalAccessException {

        RedisStandaloneConfiguration configuration = 
                (RedisStandaloneConfiguration) FieldUtils.readField(redisConnectionFactory,
                   "configuration", true);

        System.out.println("password present: " + configuration.getPassword().isPresent());

        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);

        return redisTemplate;
    }

}

As mentioned above, the password is provided when running this configuration with Spring Boot 2 (2.7.12).

Thanks and cheers Alex

Comment From: mhalbritter

Thanks for the report, I've edited your description to replace "guys" with "team". While it may seem like a small thing, some people feel excluded by "guys" and we don't want them to.

Comment From: snicoll

@vuzem I am confused that you're saying it works with Spring Boot 2.7. In Spring Boot 2.7, the property was spring.redis.url and was changed to spring.data.redis.url. Can you please double check and attach a small sample rather than a code snippet.

Comment From: vuzem

Hi @snicoll,

thanks for your answer. Sorry for not being precise enough, for Spring Boot 2, the property needs to be spring.redis.url of course. I have attached two sample projects including the RedisConfig from above.

Sample project with Spring Boot 2.7.12 and property spring.redis.url: RedisPropertiesSpringBoot2.zip

Sample project with Spring Boot 3.1.0 and property spring.data.redis.url: RedisPropertiesSpringBoot3.zip

Cheers Alex

Comment From: scottfrederick

Thanks very much for the sample. The Redis URL in the sample is redis://password@redis-host:6379, which has a userinfo with a password but no username. The changes in 3.1 currently require the userinfo to contain a :, so a URL like redis://:password@redis-host:6379 (with a : before the password) is likely to work.

The previous code assumed that a userinfo without a : contained just a password, which matches the documentation for the Lettuce driver. We should restore this behavior.