Spring 网关无法连接 Redis



Spring网关无法读取或连接redis…得到这样的错误:

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

问题是redis不是在本地配置的,而是在特定的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

我不能通过telnet连接到redis,但显然它甚至没有尝试连接到远程主机,而是连接到本地…

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()
}

为什么可能是原因?

多亏了@ toifasc,修复方法是将redis配置更改为spring.data.redis...

相关内容

  • 没有找到相关文章

最新更新