4
  • Spring-boot: 2.0.3.RELEASE
  • lettuce-core: 5.0.4.RELEASE
  • spring-data-redis: 2.0.8.RELEASE

So first of all my issue is solved I just don't understand why and it bothers me, so some clarification around this is appreciated.

I have this Redis Configuration in one of the micro-service I'm working on:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.core.resource.DefaultClientResources;

@Configuration
public class LettuceConfig {

    @Bean(destroyMethod = "shutdown")
    ClientResources clientResources() {
        return DefaultClientResources.create();
    }

    @Bean(destroyMethod = "shutdown")
    RedisClient redisClient(ClientResources clientResources) {
        String host = System.getenv("spring_redis_host") != null ? System.getenv("spring_redis_host") : "127.0.0.1";
        String port = System.getenv("spring_redis_port") != null ? System.getenv("spring_redis_port") : "6379";
        String password = System.getenv("spring_redis_password") != null ? System.getenv("spring_redis_password") : "";
        Boolean isLocal = host.equals("127.0.0.1");

        RedisURI redisUri = RedisURI.Builder.redis(host).withSsl(!isLocal).withPassword(password).withPort(Integer.parseInt(port))
                .build();
        return RedisClient.create(clientResources, redisUri);
    }

    @Bean(destroyMethod = "close")
    StatefulRedisConnection<String, String> connection(RedisClient redisClient) {
        return redisClient.connect();
    }
}

After I added actuator to the project I realized that the service couldn't connect to the remote Redis in AWS and the service throwed the following Exception:

java.io.IOException: Connection reset by peer

After a quick google search most of the answers suggested that the problem is around the SSL connection I have, but I was confused since the RedisURI contains the withSsl function call.

Just out of curiosity I added the following property to my application.properties file, since I'm using property based Redis configuration in the other services and I knew it works.

spring.redis.ssl=true

Now this solved my problem, but I don't understand why this approach is working and the RedisURI version is not.

Could somebody provide me an explanation, who has a clear understanding about the following situation please?

I can share more from the logs if needed. Thank you!

gabkov
  • 342
  • 5
  • 9
  • I have the same problem. Are you saying that just adding the spring.redis.ssl works even for the RedisURI version? – falcon Jan 27 '21 at 23:11

0 Answers0