【解决】io.lettuce.core.RedisCommandTimeoutException: Command timed out

关注微信公众号“假装正经的程序员

springboot(spring也一样的)整个redis 的时候报如下错误:

org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:70) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:257) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnection.pSubscribe(LettuceConnection.java:747) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.eventuallyPerformSubscription(RedisMessageListenerContainer.java:783) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.run(RedisMessageListenerContainer.java:750) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out
	at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114) ~[lettuce-core-5.0.2.RELEASE.jar:na]
	at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:62) ~[lettuce-core-5.0.2.RELEASE.jar:na]
	at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) ~[lettuce-core-5.0.2.RELEASE.jar:na]
	at com.sun.proxy.$Proxy70.psubscribe(Unknown Source) ~[na:na]
	at org.springframework.data.redis.connection.lettuce.LettuceSubscription.doPsubscribe(LettuceSubscription.java:54) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.connection.util.AbstractSubscription.pSubscribe(AbstractSubscription.java:130) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnection.pSubscribe(LettuceConnection.java:745) ~[spring-data-redis-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	... 3 common frames omitted

错误原因:连接超时时间设置的过于短暂(我这边设置成了0),修改为5000左右即可

# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=192.168.30.103
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

  • 14
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 36
    评论
这个错误表示在执行 Redis 命令时超时了。RedisCommandTimeoutExceptionLettuce 客户端库中的异常类,它指示 Redis 命令执行超时。 在默认情况下,Lettuce 客户端库设置了一个命令执行的超时时间,如果 Redis 服务器在该时间内没有返回结果,则会抛出这个异常。在你的情况下,命令执行时间超过了 100 秒。 有几个可能的原因导致命令执行超时: 1. Redis 服务器过载:如果 Redis 服务器处理大量请求或者数据量过大,可能导致命令执行时间增长。可以通过监控 Redis 服务器的负载情况来验证这一点。 2. 网络延迟:如果 Redis 服务器和 Lettuce 客户端之间的网络延迟增加,命令执行时间会增加。可以通过检查网络连接和延迟来排除这个问题。 3. 命令复杂性:某些复杂的 Redis 命令(如聚合操作或大规模数据操作)可能需要更长的执行时间。可以检查你正在执行的命令是否包含复杂操作。 为了解决这个问题,你可以尝试以下几个步骤: 1. 检查 Redis 服务器的性能和负载情况,确保它没有过载。 2. 检查网络连接和延迟,确保网络通畅。 3. 优化你的 Redis 命令,尽量减少复杂操作或者将其拆分成多个较小的操作。 4. 调整 Lettuce 客户端的命令执行超时时间,可以根据你的实际需求增加超时时间。 如果问题仍然存在,你可能需要进一步调查和诊断,可能需要检查日志以获取更多细节,或者考虑升级 Redis 服务器的硬件配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 36
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东天里的冬天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值