问答

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

作者:admin 2021-06-07 我要评论

使用的springboot包是2.2.1,lettuce是5.2.1 yml相关配置 redis: database: 0 host: port: 6379 password: timeout: 5000 lettuce: pool: max-active: 8 max-wai...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

使用的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)
###

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

###

换成jedis吧,我记得原先也遇到过这个问题,没有解决,最后换掉后没有再出现此问题。


可能和网络有关,大体可参考:

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • springboot使用lettuce做redis客户端,

    springboot使用lettuce做redis客户端,

  • java Mission Control里的mbean操作问

    java Mission Control里的mbean操作问

  • 前端面试:设计一个数据结构

    前端面试:设计一个数据结构

  • 使用docker-compose搭建redis哨兵,启

    使用docker-compose搭建redis哨兵,启

腾讯云代理商
海外云服务器