前言
最近找了一下终于解决了 Redisson 的 RedisTimeoutException
报错问题,在此记录一下。
参考目录
问题说明
在使用框架的时候,如果长时间没有进行操作,就会在控制台出现 RedisTimeoutException
异常。异常信息如下:
2022-09-19 14:08:30 [redisson-timer-4-1] ERROR o.r.c.handler.PingConnectionHandler - Unable to send PING command over channel: [id: 0xde1b1d38, L:/127.0.0.1:7995 - R:localhost/127.0.0.1:6379]
org.redisson.client.RedisTimeoutException: Command execution timeout for command: (PING), params: [], Redis client: [addr=redis://localhost:6379]
at org.redisson.client.RedisConnection.lambda$async$0(RedisConnection.java:244)
at io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:715)
at io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34)
at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:703)
at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:790)
at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:503)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
虽然不影响使用,但是会一直在控制台打印,看着很难受,找了一圈之后终于找到了解决方法。
问题解决方法
修改 Redisson 配置文件 RedisConfig
增加配置:
.setPingConnectionInterval(10000)
需要注意的是 Redisson 版本,Issues 中解决方法的版本是 3.14.0
,在框架 V3.5.0 中 Redisson 版本 3.16.7
,设置之后不生效,但是改为和 V4.3.0 一样的最新版 3.17.6
后不再出现报错。
默认的设置是 30s,修改之后是 10s。