springboot使用lettuce做redis客户端,一段时间后command timed out

使用的springboot包是2.2.1,lettuce是5.2.1

yml相关配置
 redis:
    database: 0
    host: 
    port: 6379
    password: 
    timeout: 5000
    lettuce:
      pool:
        max-active: 8
        max-wait: -1
        max-idle: 8
        min-idle: 0
服务器中redis相关配置
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 0

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

这里我把keepalive也设置成0了,但是之前默认的300也不行,就项目刚启动的时候能连,我跑了个定时任务,5分钟执行一次,第二次他就超时了

org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 5 second(s)
阅读 21.6k
2 个回答

发现一个问题,我本来是用定时任务来取redis里面的数据的,5分钟一次,只有项目刚启动的那一次可以连接,后面的基本都command timed out after xx seconds了。
但是我把定时任务改成了一分钟一次的话,他就一直不会断。看来太久不操作之后他会自动断掉,而且不会重新连接。有什么办法可以解决吗

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题