Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Unable to connect to Redis,RedisConnectionException: Unable to connect to {hostName}:6379/:6379*

$
0
0

I'm trying to configure a redis connection within my SpringBoot project.The application starts up without any issues, but when I try to test any Redis operation, specifically when making a call to a REST controller that actually invokes the repository, I keep encountering the same error.

Here are the versions I'm using in my pom.xml:

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.6</version><relativePath /></parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

Below is the configuration class I use for connecting to Redis:

@Configuration@RequiredArgsConstructorpublic class RedisConfigurationBuilder {    private final RedisProperties redisProperties;    @Bean    public RedisConnectionFactory redisConnectionFactory() {        try {            RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();            redisStandaloneConfiguration.setHostName(redisProperties.getHost());            redisStandaloneConfiguration.setPort(redisProperties.getPort());            redisStandaloneConfiguration.setUsername(redisProperties.getUsername());            redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));            LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().useSsl().and()                    .commandTimeout(Duration.ofSeconds(2)).build();            return new LettuceConnectionFactory(redisStandaloneConfiguration, clientConfig);        } catch (Exception e) {            throw new RuntimeException("Failed to configure Redis", e);        }    }    @Bean    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {        RedisTemplate<Object, Object> template = new RedisTemplate<>();        template.setConnectionFactory(connectionFactory);        template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());        template.setKeySerializer(new StringRedisSerializer());        template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());        return template;    }}

Note: In the stack trace, I've replaced the real hostname with {hostName} just to hide the actual server I'm connecting to. The error message is as follows:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to {hostName}:6379/:6379

And this is the stack trace of the error I keep getting:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to {hostName}:6379/:6379** at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1689) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1597) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1383) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to {hostName}/:6379 at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:330) at io.lettuce.core.RedisClient.connect(RedisClient.java:216) at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115) at java.base/java.util.Optional.orElseGet(Optional.java:364) at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1595) ... 77 common frames omitted Caused by: java.lang.IllegalArgumentException: Host has a port: {hostName}:6379 at io.lettuce.core.internal.LettuceAssert.isTrue(LettuceAssert.java:222) at io.lettuce.core.internal.HostAndPort.of(HostAndPort.java:57) at io.lettuce.core.SslConnectionBuilder.toHostAndPort(SslConnectionBuilder.java:109) at io.lettuce.core.SslConnectionBuilder.build(SslConnectionBuilder.java:99) at


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>