赞
踩
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。