2

I am getting Unable to connect to Redis;nested exception is io.lettuce.core.RedisConnectionException using RedisTemplate error when I try to connect azure redis cache from my spring reactive application.

I have configured below in properties file

spring.redis.host=hostName 
spring.redis.port=6379 
spring.redis.password=password

also tried java based configuration using LettuceConnectionFactory

Tushar
3,6759 gold badges31 silver badges51 bronze badges
asked Aug 25, 2020 at 4:54
1

2 Answers 2

1

I have encountered the same problem when enabling password authentication in AWS ElastiCache because of not using SSL for the Redis client.

Bellow RedisConfig.java uses SSL to connect and my error disappeared. I am using Spring Reactive by the way.

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Setter
public class RedisConfig {
 private String host;
 private String password;
 @Bean
 @Primary
 public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory(RedisConfiguration defaultRedisConfig) {
 LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
 .useSsl().and()
 .commandTimeout(Duration.ofMillis(60000)).build();
 return new LettuceConnectionFactory(defaultRedisConfig, clientConfig);
 }
 @Bean
 public RedisConfiguration defaultRedisConfig() {
 RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
 config.setHostName(host);
 config.setPassword(RedisPassword.of(password));
 return config;
 }
}
answered Dec 16, 2020 at 2:27
Sign up to request clarification or add additional context in comments.

Comments

0

Make Sure to use jedisConFactory.setUseSsl(true); for aws redis connection. By Default ssl is off for redis connection.

 @Bean
 JedisConnectionFactory jedisConnectionFactory() {
 final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
 jedisPoolConfig.setMaxTotal(300);
 jedisPoolConfig.setMaxIdle(20);
 jedisPoolConfig.setMaxWaitMillis(2000);
 jedisPoolConfig.setBlockWhenExhausted(true);
 JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(jedisPoolConfig);
 jedisConFactory.setHostName(redisHost);
 jedisConFactory.setPort(redisPort);
 jedisConFactory.setPassword(redisPassword);
 jedisConFactory.setUsePool(true);
 jedisConFactory.setTimeout(redisTimeout);
 jedisConFactory.setUseSsl(redisSsl);
 return jedisConFactory;
 }
 @Bean(name = "redisTemplate")
 public RedisTemplate<String, Object> redisTemplate() {
 RedisTemplate<String, Object> template = new RedisTemplate<>();
 template.setConnectionFactory(jedisConnectionFactory());
 //template.setEnableTransactionSupport(true);
 template.setExposeConnection(true);
 template.afterPropertiesSet();
 return template;
 }
Tushar
3,6759 gold badges31 silver badges51 bronze badges
answered Jul 12, 2023 at 6:38

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.