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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现一个问题,我本来是用定时任务来取redis里面的数据的,5分钟一次,只有项目刚启动的那一次可以连接,后面的基本都command timed out after xx seconds了。
但是我把定时任务改成了一分钟一次的话,他就一直不会断。看来太久不操作之后他会自动断掉,而且不会重新连接。有什么办法可以解决吗
换成
jedis
吧,我记得原先也遇到过这个问题,没有解决,最后换掉后没有再出现此问题。可能和网络有关,大体可参考: