java - Redis:关闭其中一个 Redis 主节点时,Spring Boot 应用程序请求不断失败
问题描述
这些天被redis问题阻止了,提前感谢您的任何建议。以下是一些细节:
Evn:Spring boot 2.0.3.RELEASE,Redis 3.0.6 集群(3 master,3 slave),
starter:spring-boot-starter-data-redis(默认带有spring boot的版本),表示应用会使用letture作为redis客户端
错误场景:
启动应用程序并发送一些请求,一切正常
在主节点上停止,相应的从节点将需要大约 20 秒才能故障转移成为主节点,这也很好。
在前 20 秒(故障转移时间)期间,如果继续发送请求。
- 20年代,请求失败,这是意料之中的
- 20s后(slave变成master),请求还是失败,这是意料之外的
在前 20 秒(故障转移时间)期间,如果没有发送请求。从机成为主机后,最后的请求就正常了。
在上面的步骤中没有写操作
配置:
conf
cache:
type: redis
redis:
cluster: ip1:port(m),ip1:port(s),ip2:port(m),ip2:port(s),ip3:port(m),ip3:port(s)
max-redirects: 3
password: xxxx
timeout: 1000
pool:
max-active: 500
max-wait: 1500
代码:只创建一个简单的CacheManager
bean
java
@Bean
public CacheManager cacheManager(RedisConnectionFacotry redisConnectionFacotry){
return new RedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFacotry),
redisCacheConfig) // set serializer and timeout
}
我们在代码中使用了spring cache,带有如下注释:@CachePut
等。redis中的总数据小于10M,redis的总容量为2G。
需要你的帮助:)
解决方案
当我们从生菜变为绝地时,问题就出现了,没有找到根本原因。
推荐阅读
- mysql - 如何更改现有 MySQL 数据库的排序规则?
- scala - Int 和 Long 的 Scala 中值函数
- amazon-web-services - 在 AWS 控制台中查看基于资源的策略
- c# - 如何将 2D 星球上的角色对齐在星球表面直立?
- maven - 在运行时提供 Maven 值
- angular - Angular:持久的用户数据
- ios - 无法以编程方式同时满足约束。斯威夫特 iOS
- perl - 将空格替换为 0
- graphql - Graphql 属于关系
- postgresql - 更改为 pg_hba.conf 和 postgresql.conf 以使用 pgadmin 与所有用户连接后无法启动 postgres 服务器