520886:爱,是永不落幕的星辰大海

核心内容摘要

火影忍者奖励网站
告别高昂费用,永久免费!黄冈建站迎来革新,您的在线梦想触手可及

探索东方神秘之境:日本护肤的“精”致哲学

问题描述Redis Cluster集群当master宕机主从切换客户端报错 timed out

原因SpringBoot

X版本开始Redis默认的连接池都是采用的Lettuce。

当节点发生改变后Letture默认是不会刷新节点拓扑的。

解决方案

1 方案一把lettuce换成jedis只需要在pom.xml里调整一下依赖的引用dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-data-redis/artifactId version

2.

1.

RELEASE/version !-- 不用lettuce ,用jedis -- exclusions exclusion groupIdio.lettuce/groupId artifactIdlettuce-core/artifactId /exclusion /exclusions /dependency dependency groupIdredis.clients/groupId artifactIdjedis/artifactId version

3.

0-m4/version /dependency

2 方案二刷新节点拓扑视图Redis节点异常服务端的Redis集群拓扑被刷新了Java程序没有获取到新的拓扑。

Lettuce官方文档中关于Redis Cluster的相关说明Lettuce处理Moved和Ask永久重定向由于命令重定向你必须刷新节点拓扑视图。

而自适应拓扑刷新Adaptive updates与定时拓扑刷新Periodic updates是默认关闭的可以通过如下代码打开。

https://github.com/lettuce-io/lettuce-core/wiki/Redis-Cluster#user-content-refreshing-the-cluster-topology-viewLettuce修改代码如下package com.montnets.common.redis; import io.lettuce.core.ClientOptions; import io.lettuce.core.cluster.ClusterClientOptions; import io.lettuce.core.cluster.ClusterTopologyRefreshOptions; import org.apache.commons.pool

impl.GenericObjectPoolConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.RedisNode; import org.springframework.data.redis.connection.RedisPassword; import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; import org.springframework.stereotype.Component; import java.time.Duration; import java.util.HashSet; import java.util.List; import java.util.Set; Component public class RedisPoolConfig { Autowired private RedisProperties redisProperties; public GenericObjectPoolConfig? genericObjectPoolConfig(RedisProperties.Pool properties) { GenericObjectPoolConfig? config new GenericObjectPoolConfig(); config.setMaxTotal(properties.getMaxActive()); config.setMaxIdle(properties.getMaxIdle()); config.setMinIdle(properties.getMinIdle()); if (properties.getTimeBetweenEvictionRuns() ! null) { config.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRuns().toMillis()); } if (properties.getMaxWait() ! null) { config.setMaxWaitMillis(properties.getMaxWait().toMillis()); } return config; } Bean(destroyMethod destroy) public LettuceConnectionFactory lettuceConnectionFactory() { //开启 自适应集群拓扑刷新和周期拓扑刷新 ClusterTopologyRefreshOptions clusterTopologyRefreshOptions ClusterTopologyRefreshOptions.builder() // 开启全部自适应刷新 .enableAllAdaptiveRefreshTriggers() // 开启自适应刷新,自适应刷新不开启,Redis集群变更时将会导致连接异常 // 自适应刷新超时时间(默认30秒) .adaptiveRefreshTriggersTimeout(Duration.ofSeconds(

) //默认关闭开启后时间为30秒 // 开周期刷新 .enablePeriodicRefresh(Duration.ofSeconds(

) // 默认关闭开启后时间为60秒 ClusterTopologyRefreshOptions.DEFAULT_REFRESH_PERIOD 60 .enablePeriodicRefresh(Duration.ofSeconds(

) .enablePeriodicRefresh().refreshPeriod(Duration.ofSeconds(

) .build(); // https://github.com/lettuce-io/lettuce-core/wiki/Client-Options ClientOptions clientOptions ClusterClientOptions.builder() .topologyRefreshOptions(clusterTopologyRefreshOptions) .build(); LettuceClientConfiguration clientConfig LettucePoolingClientConfiguration.builder() .poolConfig(genericObjectPoolConfig(redisProperties.getJedis().getPool())) //.readFrom(ReadFrom.MASTER_PREFERRED) .clientOptions(clientOptions) .commandTimeout(redisProperties.getTimeout()) //默认RedisURI.DEFAULT_TIMEOUT 60 .build(); ListString clusterNodes redisProperties.getCluster().getNodes(); SetRedisNode nodes new HashSetRedisNode(); clusterNodes.forEach(address - nodes.add(new RedisNode(address.split(:)[0].trim(), Integer.valueOf(address.split(:)[1])))); RedisClusterConfiguration clusterConfiguration new RedisClusterConfiguration(); clusterConfiguration.setClusterNodes(nodes); clusterConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword())); clusterConfiguration.setMaxRedirects(redisProperties.getCluster().getMaxRedirects()); LettuceConnectionFactory lettuceConnectionFactory new LettuceConnectionFactory(clusterConfiguration, clientConfig); // lettuceConnectionFactory.setShareNativeConnection(false); //是否允许多个线程操作共用同一个缓存连接默认truefalse时每个操作都将开辟新的连接 // lettuceConnectionFactory.resetConnection(); // 重置底层共享连接, 在接下来的访问时初始化 return lettuceConnectionFactory; } }AI大模型学习福利作为一名热心肠的互联网老兵我决定把宝贵的AI知识分享给大家。

至于能学习到多少就看你的学习毅力和能力了 。

我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。

全套AGI大模型学习路线AI大模型时代的学习之旅从基础到前沿掌握人工智能的核心技能因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获取

640套AI大模型报告合集这套包含640份报告的合集涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。

无论您是科研人员、工程师还是对AI大模型感兴趣的爱好者这套报告合集都将为您提供宝贵的信息和启示。

因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获

AI大模型经典PDF籍随着人工智能技术的飞速发展AI大模型已经成为了当今科技领域的一大热点。

这些大型预训练模型如GPT-

BERT、XLNet等以其强大的语言理解和生成能力正在改变我们对人工智能的认识。

那以下这些PDF籍就是非常不错的学习资源。

因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获

AI大模型商业化落地方案因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获作为普通人入局大模型时代需要持续学习和实践不断提高自己的技能和认知水平同时也需要有责任感和伦理意识为人工智能的健康发展贡献力量。

糖心少女VLOG小妈吃雪糕-糖心少女VLOG小妈吃雪糕应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123