redisson

redisson client fails connect to redis-server on <my.ip.addr>Error connect to localhost/127.0.0.1:6379


I am trying to use redisson client (java) to connect to my test redis-server

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-boot-starter</artifactId>
    <version>3.23.2</version>
</dependency>

I have checked that my redis-server is up and running on a linux box (<my.ip.addr>) on the network.

My redison client is getting the error below (even though I am using redisson client with "singleServerConfig" with address: "redis://<my.ip.addr>:6379"

Error:

Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redisson' threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379
...
Caused by: org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379
    at org.redisson.connection.pool.ConnectionPool.lambda$createConnection$0(ConnectionPool.java:132)
    at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)

Nowhere in my redisson client code did I mention localhost, not sure why is it trying to connect to Redis server at localhost/127.0.0.1:6379 that instead of <my.ip.address> and failing.

I checked my redis-server config, it has bind <my.ip.address> specified along with protected-mode no (just for initial testing)?

On my redisson client I am using Config.fromYAML("/redison-config.yml") and that seems correct with "singleServerConfig" with address: "redis://<my.ip.addr>:6379"

I have tested network connectivity to the linux box (<my.ip.addr>) where redis-server is running.

What else do I check ?

I am just testing out something in dev mode using redis so the setup is not production grade at the moment.

Trying to use org.redisson.config.Config to connect to my redis-server running on <my.ip.address> using singleServerConfig and address: "redis://my.io.addr:6379"

On my springboot app initially I see in the logs:

2023-09-07 10:10:15,228 | INFO  | org.redisson.connection.pool.MasterPubSubConnectionPool:140 |  |  | 1 connections initialized for <my.ip.addr>/<my.ip.addr>:6379
2023-09-07 10:10:20,849 | INFO  | org.redisson.connection.pool.MasterConnectionPool:140 |  |  | 10 connections initialized for <my.ip.addr>/<my.ip.addr>:6379

But then the app start fails while RedissonAutoConfiguration is creating bean with name 'redissonConnectionFactory' with the following error:

Error:

2023-09-07 10:10:26,281 | WARN  | org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext:591 |  |  | 
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'redisTemplate' defined in class path resource [org/redisson/spring/starter/RedissonAutoConfiguration.class]: 
Unsatisfied dependency expressed through method 'redisTemplate' parameter 0; 
nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'redissonConnectionFactory' defined in class path resource [org/redisson/spring/starter/RedissonAutoConfiguration.class]: 
Unsatisfied dependency expressed through method 'redissonConnectionFactory' parameter 0; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisson' defined in class path resource [org/redisson/spring/starter/RedissonAutoConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redisson' threw exception; nested exception is 
org.redisson.client.RedisConnectionException: 
Unable to connect to Redis server: localhost/127.0.0.1:6379
...
2023-09-07 10:10:26,681 | ERROR | org.springframework.boot.SpringApplication:821 |  |  | Application run failed

What is confounding me is where is localhost/127.0.0.1 coming from when I did specify the redis server address using <my.ip.addr>


Solution

  • Figured out that since I am using redisson spring boot starter :

    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson-spring-boot-starter</artifactId>
        <version>3.23.2</version>
    </dependency>
    

    which internally uses RedissonAutoConfiguration for spring, that reads spring @ConfigurationProperties(prefix = "spring.redis") in class RedisProperties, I had to fix the spring application properties as mentioned here: https://developer.redis.com/develop/java/redis-and-spring-course/lesson_2/#redis-template

    So adding this snippet to the spring boot application yaml was needed and that did the trick:

      redis:
        host: <my.ip.address>
        port: 6379
      autoconfigure:
        exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration