首页 > 解决方案 > 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客户端


错误场景:

  1. 启动应用程序并发送一些请求,一切正常

  2. 在主节点上停止,相应的从节点将需要大约 20 秒才能故障转移成为主节点,这也很好。

  3. 在前 20 秒(故障转移时间)期间,如果继续发送请求。

    • 20年代,请求失败,这是意料之中的
    • 20s后(slave变成master),请求还是失败,这是意料之外的
  4. 在前 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


代码:只创建一个简单的CacheManagerbean

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。

需要你的帮助:)

标签: javaspringspring-bootcachingredis

解决方案


当我们从生菜变为绝地时,问题就出现了,没有找到根本原因。


推荐阅读