当前位置:   article > 正文

SpringBoot Caused by: io.lettuce.core.RedisCommandTimeoutException: Command 连接Redis经常报错

io.lettuce.core.rediscommandtimeoutexception: command timed out after 1 minu

SpringBoot 2.X版本整合 Redis时,偶尔出现连接超时情况

 

2.x 版本自带的Redis客户端是 lettuce  

 

异常信息为:

Command timed out after 1 minute(s)

 

百度解决方案各种不靠谱,研究源码,在结合netty的使用方式如下方式修改即可:

@Bean
public LettuceConnectionFactory redisConnectionFactory() {
    ClientOptions clientOptions = ClientOptions.builder()
            .autoReconnect(true)
            .cancelCommandsOnReconnectFailure(false)
            .disconnectedBehavior(ClientOptions.DisconnectedBehavior.DEFAULT)
            .pingBeforeActivateConnection(true)
            .publishOnScheduler(true)
            .timeoutOptions(TimeoutOptions.create())
            .socketOptions(SocketOptions.builder().connectTimeout(properties.getTimeout()).keepAlive(true).build())
            .build();
    RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration();
    standaloneConfiguration.setHostName(prop
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/461687
推荐阅读
相关标签
  

闽ICP备14008679号