Redis command timed out nested exception is io.lettuce.core.RedisCommandTimeoutException

2023-11-10

报错如下:

ERROR org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 500 millisecond(s)
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:70)
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
	at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
	at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
	at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268)
	at org.springframework.data.redis.connection.lettuce.LettuceListCommands.convertLettuceAccessException(LettuceListCommands.java:490)
	at org.springframework.data.redis.connection.lettuce.LettuceListCommands.lLen(LettuceListCommands.java:159)
	at org.springframework.data.redis.connection.DefaultedRedisConnection.lLen(DefaultedRedisConnection.java:465)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	****
Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 500 millisecond(s)
	at io.lettuce.core.ExceptionFactory.createTimeoutException(ExceptionFactory.java:51)
	at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114)
	at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:69)
	at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
	at com.sun.proxy.$Proxy196.llen(Unknown Source)
	at org.springframework.data.redis.connection.lettuce.LettuceListCommands.lLen(LettuceListCommands.java:157)
	... 134 more

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

解决办法:

  • 设置超时时间
redis:
    port: 6379
    jedis:
      pool:
        max-active: 50
        max-wait: 5000
        max-idle: 50
        min-idle: 0
    timeout: 500
    host: 47.100.21.110

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

  • 更改依赖
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

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

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.data</groupId>
		<artifactId>spring-data-redis</artifactId>
	</dependency>
	<dependency>
		<groupId>redis.clients</groupId>
		<artifactId>jedis</artifactId>
	</dependency>
</dependencies>

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

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-redis</artifactId>
      <version>2.1.4.RELEASE</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>jcl-over-slf4j</artifactId>
          <groupId>org.slf4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.lettuce</groupId>
      <artifactId>lettuce-core</artifactId>
      <version>5.1.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

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

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-redis</artifactId>
	<exclusions>
		<exclusion>
			<groupId>io.lettuce</groupId>
			<artifactId>lettuce-core</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
</dependency>

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

补充(深入一点点,个人理解,勿喷)

因为上文是我在版本升级的过程中遇到的,所以当时为了稳定还是继续使用的jedis连接池,但是实际上升级之后应该转向lettuce连接池,毕竟lettuce更好。
修改依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 如果使用Lettuce作为连接池,需要引入commons-pool2包,否则会报错bean注入失败 -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>

修改配置文件

spring:
  redis: 
    port: 6379
    lettuce:
      pool:
        max-active: 500
        max-wait: 500
        max-idle: 500
        min-idle: 0
    timeout: 500
    host: 100.10.10.10
    password: password
分析
@Configuration
@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties(RedisProperties.class)
@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })
public class RedisAutoConfiguration {

首先是加载顺序。
在这里插入图片描述
同时我在@ConditionalOnClass(RedisClient.class)@ConditionalOnClass({ GenericObjectPool.class, JedisConnection.class, Jedis.class })类里面打断点,发现仅RedisClient执行了,这让我明白为啥LettuceConnectionConfiguration配置生效,但是我没明白RedisClient为啥执行。。。。项目刚启动就进来这里,再上一层我实在没找到,希望哪位研究到这里可以给个反馈。

我想要抛出LettuceConnectionConfiguration配置时失效,有异常信息。

此文仅做记录,尚未分析原因,后续补充。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Redis command timed out nested exception is io.lettuce.core.RedisCommandTimeoutException 的相关文章

随机推荐

  • 翁凯c语言作业10-1

    include
  • 搭建一个简单的https服务

    为了测试ab工具压测https接口 简单搭了一下https 记录一下过程 环境准备 在docker中建了3个容器 A 证书颁发 CA B 服务端 C 客户端 docker run d name ca centos centos7 bin b
  • mac解决mysql忘记密码的问题(亲测有效)

    打开终端依次执行如下命令 第一步 进入mysql服务 sudo usr local mysql support files mysql server stop 第一步 进入mysql的bin目录 cd usr local mysql bin
  • nginx多级代理

    文章目录 一 实验步骤 1 docker config创建3台nginx配置文件 2 集群node节点打标签 3 docker compose编排文件 4 在manager节点创建目录 5 部署服务 6 访问测试 总结 测试环境说明 基于d
  • 解决git:fatal:Unable to create".../.git/index.lock" 的错误

    问题描述 在使用git 进行提交时 出现上面这个报错 导致无法提交 报错大致意思就是创建index lock文件失败 因为已经存在index lock文件了 index lock文件是在 git下面 而 git是一般是隐藏的 那么可以通过以
  • std::enable_shared_from_this消除异步回调引发的野指针问题

    std enable shared from this这个C 组件完美解决了异步回调发生时宿主对象销毁的问题 C 提供了lambda表达式和各种异步函数 std thread std async或者其他框架api都提供了异步回调方法 特别是
  • js实现数组去重、比较两数组得出重复部分

    数组去重的两种方法 1 用新对象来存储 对象的key值为数组元素 var removeDup function old var arr 1 2 3 4 3 4 5 var o for var i 0 i lt arr length i va
  • Android MVC MVP MVVM

    浅谈 MVP in Android MVP模式解析实践 Android DataBinding库 MVVM设计模式
  • 浏览器兼容性测试工具

    相关连接 浏览器兼容性概述 目录 一 浏览器兼容性测试工具 1 0 IETester 免费 exe 1 1 SuperPreview 收费 exe 1 2 Adobe Browserlab 在线测试 1 3 BrowserStack 在线测
  • 从HTTP 2.0想到的关于传输层协议的一些事

    0 HTTP协议的历史我也不知道 1 关于HTTP 2 0收到了订阅的邮件 头版是说HTTP 2 0的内容 我本人不是很关注HTTP这一块儿 但是闲得无聊时也会瞟两眼的 HTTP 2 0的最大改进我觉得有两点 第一 新增了帧层 帧层的好处在
  • ThinkPHP3.2微信JSSDK签名配置config信息

    ThinkPHP3 2 controller代码 微信jssdk踩坑记 必须在服务器部署才有用 1 配置js接口安全域名不要加http 等 大坑 2 用appid和appsecret发起请求换取access token并将其全局缓存 3 用
  • 发布自己写的python包(得瑟)

    如何把自己写的包发布到pipy给别人用呢 网上一堆教程 众所周知网上教程都比较长 得耐心看完 学会了消化之后变成自己的了记录一下 第一步包的目录结构 抄作业就完了 第二步设置setup py 有个for human的模板 老哥起名也是幽默
  • adb shell dumpsys 使用命令和来源

    一 概述 adb shell dumpsys 在Android开发中经常要用到 平时都是零碎的积累 用到什么的时候就 记录下来 最近看了一些资料 发现可以汇总所有的命令 当带某个参数的时候 就可以查看具体 的信息 本篇文章中还讲解了如何去找
  • 【二维费用的完全背包问题】

    前言 简单写一下算法设计与分析这门课的一次实验 原题要求是用0 1背包来做 但是老师要求用完全背包来做 一 完全背包与0 1背包有什么区别 0 1背包 顾名思义对于每件物品只能拿1次或者0次 而完全背包对于每件物品的拿取没有次数限制 二 二
  • beyond compare破解方法

    BeyondCompare4相关操作 1 修改文件C Program Files Beyond Compare 4 BCUnrar dll 这个文件重命名或者直接删除 2 将以下操作保存为bat文件 然后双击运行即可 reg delete
  • java多态-对象多态

    对象多态 动态绑定 动态连接 package com leoworld polymorphism 多态的成员访问特点 A 成员变量 编译看左边 运行看左边 B 成员方法 编译看左边 运行看右边 为什么呢 因为成员方法有重写 而变量没有 C
  • 计算机dvd驱动错误,修正:一个错误发生在弹出的CD/DVD驱动器在Windows 10

    如果您使用的是可移动媒体 比如DVD或USB驱动器 有时您可能会在从系统中删除或弹出它时遇到麻烦 通常 Windows会拒绝当前正在使用的驱动器的请求 这意味着你应该首先关闭程序 应用程序 进程使用驱动器上的内容 然后你应该继续试着弹出驱动
  • 【Software Engineering】【期末复习知识点】【2023春】【仅供参考】

    文章目录 类型 总分占比 出勤 10 平时作业 2 5 10 期中考试 10 期末考试 70 附加分 提问加分 题型 题量 分值 预测 选择 15 2 填空 5 2 软件工程方法学 名词解释 5 2 软件危机 软件生命周期 简答 3 5 综
  • html中表单form的语法结构以及释义

    1 form属性
  • Redis command timed out nested exception is io.lettuce.core.RedisCommandTimeoutException

    报错如下 ERROR org springframework dao QueryTimeoutException Redis command timed out nested exception is io lettuce core Red