birjoossh
birjoossh

Reputation: 83

Cannot connect to redis using spring and lettuce

I am struggling to find what could be wring here; need help. I am using spring-data-redis 2.4.1

RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration()
redisStandaloneConfiguration.setHostname(hostname)
redisStandaloneConfiguration.setPort(6379)
redisStandaloneConfiguration.setPassword("password")

I then create lettuceClientConfigurationBuilder and specify clientName

I then use lettuceClientConfiguration and redisStandaloneConfiguration to create ClientConnectionFactory.

However, when we call getConnection() on the connection Factory, we get

WrongPass Invalid username-password pair

The same set of username-password works with Redis-CLI on cmd prompt.

Is there is something wrong in the way I am using in my java application?

Any pointer/hint towards solving this would be greatly appreciated.

Upvotes: 0

Views: 5930

Answers (2)

birjoossh
birjoossh

Reputation: 83

I had mistaken username for clientname set on LettuceClientConfigurationBuilder but username had to be specified on the redisstandaloneconfiguratuon. This works for me; also please note acl was introduced only after lettuce 2.4.1 so any prior version will not work.

redisStandaloneConfiguration.setUsername(connectionFactoryConfigs.getUserName());

Upvotes: 0

Rafael Estevez
Rafael Estevez

Reputation: 31

Spring Boot configures LettuceConnectionFactory for you, you can specify the connection params on the application.properties file.

spring.redis.database=0
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.password=yourPassword
spring.redis.timeout=60000

If you wanna do it programmatically, set the spring.redis.password in application.properties and try this:

@Configuration
class AppConfig {

  @Bean
  public LettuceConnectionFactory redisConnectionFactory() {

    return new LettuceConnectionFactory(new RedisStandaloneConfiguration("server", 6379));
  }
}

Upvotes: 3

Related Questions