当前位置:   article > 正文

Redis - Redis command timed out nested exception is io.lettuce.core.RedisCommandTimeoutException_redis command timed out; nested exception is io.le

redis command timed out; nested exception is io.lettuce.core.rediscommandtim

报错信息

  1. ERROR org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 500 millisecond(s)
  2. at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:70)
  3. at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
  4. at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
  5. at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
  6. at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268)
  7. at org.springframework.data.redis.connection.lettuce.LettuceListCommands.convertLettuceAccessException(LettuceListCommands.java:490)
  8. at org.springframework.data.redis.connection.lettuce.LettuceListCommands.lLen(LettuceListCommands.java:159)
  9. at org.springframework.data.redis.connection.DefaultedRedisConnection.lLen(DefaultedRedisConnection.java:465)
  10. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  11. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  12. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  13. at java.lang.reflect.Method.invoke(Method.java:498)
  14. ****
  15. Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 500 millisecond(s)
  16. at io.lettuce.core.ExceptionFactory.createTimeoutException(ExceptionFactory.java:51)
  17. at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114)
  18. at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:69)
  19. at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
  20. at com.sun.proxy.$Proxy196.llen(Unknown Source)
  21. at org.springframework.data.redis.connection.lettuce.LettuceListCommands.lLen(LettuceListCommands.java:157)
  22. ... 134 more

 

原因分析

  • 这个情况是我在将SpringBoot从1.X升级到2.X的时候产生的问题,所以大致可以猜到是版本问题。

 

解决办法

  • 设置超时时间(不推荐)
  1. redis:
  2. port: 6379
  3. jedis:
  4. pool:
  5. max-active: 50
  6. max-wait: 5000
  7. max-idle: 50
  8. min-idle: 0
  9. timeout: 500
  10. host: 47.100.21.110

这种方法无效,解决不了这个问题,我从0改到500还是报错。但是网上绝大多数都是这种方式,实际上我刚更改过来的时候有效过一阵,之后就又不行了。

  • 更改依赖(亲测有效)
  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-data-redis</artifactId>
  4. </dependency>

在SpringBoot 1.X版本的jar包依赖中,点击进去依赖项如下:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.data</groupId>
  8. <artifactId>spring-data-redis</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>redis.clients</groupId>
  12. <artifactId>jedis</artifactId>
  13. </dependency>
  14. </dependencies>

升级到SpringBoot 2.X版本之后依赖如下:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter</artifactId>
  5. <version>2.1.2.RELEASE</version>
  6. <scope>compile</scope>
  7. </dependency>
  8. <dependency>
  9. <groupId>org.springframework.data</groupId>
  10. <artifactId>spring-data-redis</artifactId>
  11. <version>2.1.4.RELEASE</version>
  12. <scope>compile</scope>
  13. <exclusions>
  14. <exclusion>
  15. <artifactId>jcl-over-slf4j</artifactId>
  16. <groupId>org.slf4j</groupId>
  17. </exclusion>
  18. </exclusions>
  19. </dependency>
  20. <dependency>
  21. <groupId>io.lettuce</groupId>
  22. <artifactId>lettuce-core</artifactId>
  23. <version>5.1.3.RELEASE</version>
  24. <scope>compile</scope>
  25. </dependency>
  26. </dependencies>

可以看到变化是从jedis依赖变成了lettuce-core依赖,而上面的报错io.lettuce.core.RedisCommandTimeoutException也是lettuce-core的异常,所以我的解决方式是先将依赖换回jedis:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-data-redis</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <groupId>io.lettuce</groupId>
  7. <artifactId>lettuce-core</artifactId>
  8. </exclusion>
  9. </exclusions>
  10. </dependency>
  11. <dependency>
  12. <groupId>redis.clients</groupId>
  13. <artifactId>jedis</artifactId>
  14. </dependency>

如上,配置文件不变,Redis连接成功,不再报错。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/461723
推荐阅读
相关标签
  

闽ICP备14008679号