redisspring-data-redislettuce

Spring data redis ignoring user credentials


I am trying to create a redis client with spring data redis with lettuce. What I am observing right is that whatever any password other than default user password doesn't work. Below is the code:-

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
            
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(host);
    redisStandaloneConfiguration.setPort(port);
    redisStandaloneConfiguration.setUsername(username);
    redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
    
    LettuceConnectionFactory lcf = new LettuceConnectionFactory(redisStandaloneConfiguration);

    lcf.setShareNativeConnection(false);
    lcf.afterPropertiesSet();
    return lcf;
}

@Bean
public RedisTemplate<String, Object> redisTemplate() {
    RedisTemplate<String, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(lettuceConnectionFactory());
    template.afterPropertiesSet();
    return template;
}

In the debug logs, I can see that it is using the username provided:

Trying to get a Redis connection for: redis://test:*******@serverA.net:12345

However, no password other than default user password works. I am able to connect with same credentials on Redis CLI. Eventually gets WRONGPASS invalid username-password pair

What is wrong with above code? Using spring boot vs 2.4.2 & lettuce-core vs 6.0.2


Solution

  • I had spring and lettuce redisearch dependencies in the pom file. Removing them resolved the issue.

    <dependency>
      <groupId>com.redislabs</groupId>
      <artifactId>lettusearch</artifactId>
      <version>2.4.4</version>
    </dependency>