若依微服务连接redis 一段时间报错,后来改成连接池后也是报错 Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 10 second(s)

发布时间 2023-03-22 21:11:21作者: BBS_自律

springBoot版本是2.x 所以呢redis客户端是lettuce,而不是jedis;

  lettuce支持异步,而且是线程安全的。

  jedis是同步的,线程不安全需要每个线程一个Jedis实例,所以一般通过连接池来使用Jedis。

我这里用的是lettuce连接池的配置还是报错了呢:

spring:
  redis:
    host: 82.156.175.242
    port: 6380
    password:
    # 连接超时时间 客户端空闲 N 秒后关闭连接(0 表示禁用)
    timeout: 10s 
    lettuce:
      pool:
        # 连接池中的最小空闲连接
        min-idle: 0
        # 连接池中的最大空闲连接
        max-idle: 8
        # 连接池的最大数据库连接数
        max-active: 8
        # #连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: -1ms        

 new BING

spring:
  redis:
    lettuce:
      pool:
        max-active: 8 #最大活跃连接数
        max-idle: 8 #最大空闲连接数
        min-idle: 0 #最小空闲连接数
        max-wait: -1ms #最大等待时间
      shutdown-timeout: 100ms #关闭超时时间

 

 

config get timeout是一个Redis命令,用于获取Redis服务器的timeout配置值1。如果你在服务器中执行不了,可能有以下几种原因:

  • 你没有正确地连接到Redis服务器,或者没有使用redis-cli工具。你可以使用redis-cli -h <host> -p <port>命令来连接到Redis服务器,然后再执行config get timeout命令。
  • 你没有足够的权限来执行config get timeout命令。这个命令需要有admin角色的权限,如果你使用了密码或者ACL来保护Redis服务器,你需要先使用auth或者acl auth命令来验证身份。
  • 你的Redis版本不支持config get timeout命令。这个命令是在Redis 2.0版本引入的,如果你的Redis版本低于2.0,你可能无法执行这个命令。你可以使用info server命令来查看Redis的版本号。

 

参考:

Redis command timed out 两种异常情况

NEW BING

 

 

-----------------------------官方issues-----------------------------