springboot-redis-tips
2020.11.20
codewindy
 热度
℃
一. 背景
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();
|
三. 参考