Redis教程

解决redis超时io.lettuce.core.RedisCommandTimeoutException: Connection timed out after 5s

本文主要是介绍解决redis超时io.lettuce.core.RedisCommandTimeoutException: Connection timed out after 5s,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

报错内容:


io.lettuce.core.RedisCommandTimeoutException: Connection initialization timed out. Command timed out after 1 minute(s)
    at io.lettuce.core.internal.ExceptionFactory.createTimeoutException(ExceptionFactory.java:65) ~[lettuce-core-6.1.4.RELEASE.jar:6.1.4.RELEASE]
    at io.lettuce.core.protocol.RedisHandshakeHandler.lambda$channelRegistered$0(RedisHandshakeHandler.java:62) ~[lettuce-core-6.1.4.RELEASE.jar:6.1.4.RELEASE]
    at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:106) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.67.Final.jar:4.1.67.Final]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]

错误原因:开始以为是spring.redis.timeout设置时间过短,增长时间也是连接超时,后来发现是因为redis连接池lettuce存在bug,

解决如下:更换连接池,使用jedis

1.首先添加jar包依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <exclusions>
        <exclusion>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </exclusion>
        <exclusion>
            <artifactId>lettuce-core</artifactId>
            <groupId>io.lettuce</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>

2.然后在application.properties文件中配置如下:

spring.redis.jedis.pool.max-wait=2000
spring.redis.jedis.pool.max-active= 8
spring.redis.jedis.pool.max-idle=9
spring.redis.jedis.pool.min-idle=0
spring.redis.jedis.pool.time-between-eviction-runs=1000


 

这篇关于解决redis超时io.lettuce.core.RedisCommandTimeoutException: Connection timed out after 5s的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!