英文:
spring gateway can't connect redis
问题
Spring网关无法读取或连接到Redis...
出现如下错误:
org.springframework.data.redis.RedisConnectionFailureException: 无法连接到Redis
...
导致原因:io.lettuce.core.RedisConnectionException:无法连接到localhost/<未解析>: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()
}
可能的原因是什么?
英文:
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?
答案1
得分: 0
感谢 @tobifasc,修复方法是更改Redis配置为 spring.data.redis...
英文:
Thanks to @tobifasc, the fix is to change redis configuration to spring.data.redis...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论