踩坑-springboot 集成redis(Lettuce 客户端超时问题)

落日映苍穹つ 2022-11-22 00:19 524阅读 0赞

原先配置是使用默认Lettuce。后来在生产环境发现会经常的超时,导致缓存不可用,而且一超时就不恢复。

后来查了些资料,网上都有这个问题,无解,都建议使用jedis。

先看下原来的配置,maven配置(项目其他配置已省略)

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-redis</artifactId>
  9. <version>2.0.0.RELEASE</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-data-redis</artifactId>
  14. <version>2.0.0.RELEASE</version>
  15. <exclusions>
  16. <exclusion>
  17. <groupId>redis.clients</groupId>
  18. <artifactId>jedis</artifactId>
  19. </exclusion>
  20. </exclusions>
  21. </dependency>

application.yml配置:

  1. spring:
  2. redis:
  3. database: 15 # Redis数据库索引(默认为0)
  4. host: 10.10.10.43 # Redis服务器地址
  5. port: 6379 # Redis服务器连接端口
  6. password: # Redis服务器连接密码(默认为空)
  7. timeout: 5000 # 连接超时时间(毫秒)
  8. pool:
  9. max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
  10. max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
  11. max-idle: 8 # 连接池中的最大空闲连接
  12. min-idle: 0 # 连接池中的最小空闲连接

会一直报错org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 500 millisecond(s)。

后来改配置,maven如下:

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-redis</artifactId>
  9. <version>2.0.0.RELEASE</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-data-redis</artifactId>
  14. <version>2.0.0.RELEASE</version>
  15. <exclusions>
  16. <!-- <exclusion>
  17. <groupId>redis.clients</groupId>
  18. <artifactId>jedis</artifactId>
  19. </exclusion> -->
  20. <exclusion>
  21. <groupId>io.lettuce</groupId>
  22. <artifactId>lettuce-core</artifactId>
  23. </exclusion>
  24. </exclusions>
  25. </dependency>
  26. <dependency>
  27. <groupId>redis.clients</groupId>
  28. <artifactId>jedis</artifactId>
  29. <version>2.9.0</version>
  30. </dependency>

application.yml配置:

  1. spring:
  2. redis:
  3. database: 15 # Redis数据库索引(默认为0)
  4. host: 10.10.10.43 # Redis服务器地址
  5. port: 6379 # Redis服务器连接端口
  6. password: # Redis服务器连接密码(默认为空)
  7. timeout: 5000 # 连接超时时间(毫秒)
  8. jedis:
  9. pool:
  10. max-active: 300
  11. max-idle: 100
  12. min-idle: 0
  13. max-wait: -1ms

总的来说是放弃了Lettuce ,使用jedis,问题能够得到解决。

发表评论

表情:
评论列表 (有 0 条评论,524人围观)

还没有评论,来说两句吧...

相关阅读

    相关 springboot记录

    使用sts,或者是官方的地址新建springboot项目,导入到myeclipse,项目pom文件第一行报错,无任何错误信息,提示unknown,尝试过换maven和jdk版本

    相关 springboot项目

    1.SpringBootApplication启动时会默认扫描主类当前包及子包,如果需要扫描主类当前包外的其他包或不扫描当前包下的特定包或类,可通过下列属性实现: @