Home
Home
文章目录
  1. 一. 背景
  2. 二. 解决
  3. 三. 参考

springboot-redis-tips

一. 背景

  • springboot2.x 之后默认redis客户端不是jedis而是lettuce但是在集群环境中如果有一个节点挂了就会导致服务不可用

二. 解决

# Example 37. Enabling periodic cluster topology view updates
RedisClusterClient clusterClient = RedisClusterClient.create(RedisURI.create("localhost", 6379));


ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
.enableAdaptiveRefreshTrigger(RefreshTrigger.MOVED_REDIRECT, RefreshTrigger.PERSISTENT_RECONNECTS)
.adaptiveRefreshTriggersTimeout(30, TimeUnit.SECONDS)
.build();

clusterClient.setOptions(ClusterClientOptions.builder()
.topologyRefreshOptions(topologyRefreshOptions)
.build());
...

clusterClient.shutdown();

三. 参考

支持一下
扫一扫,支持codewindy
  • 微信扫一扫