Search code examples
springredisspring-cloud-gateway

spring gateway can't connect redis


Spring gateway cant' read or connect to redis... Getting such error:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
...
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379

The problem is redis configured not locally but on specific ip, application.yml:

spring:
  redis:
    host: 1.2.3.4
    port: 6379
    password: passw
    database: 0
    timeout: 3000
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 2
        max-wait: 5000ms

I can't connect to redis via telnet, but obviously it's not even trying to connect to remote host, but instead connecting locally...

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.5'
    id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
sourceCompatibility = '17'
repositories {
    mavenCentral()
}
ext {
    set('springCloudVersion', "2022.0.1")
}
dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    // --- cache
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'com.github.ben-manes.caffeine:caffeine:3.1.5'
    // --- redis
    implementation group: 'org.springframework.data', name: 'spring-data-redis', version: '3.0.4'
    implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
    //
    implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
    implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}
tasks.named('test') {
    useJUnitPlatform()
}

Why could be the cause?


Solution

  • Thanks to @tobifasc, the fix is to change redis configuration to spring.data.redis...