lettuce连接超时问题

4,291 阅读1分钟

项目使用springboot搭建,涉及到redis的使用,开始经常出现『Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 10 second(s)』报错(查询、插入都会报错),查询资料知道原因是springboot2.0以上版本redis客户端默认使用lettuce,修改为使用jedis,但是性能达不到要求,又改为使用lettuce,在配置时开启了心跳。

截屏2021-11-09 上午11.54.16.png

但是发现还是会出现同样的报错,只不过查询、删除都没事,只有偶尔插入会报错。。。看到有开启每次连接前校验的设置,但是担心影响性能。

stringRedisTemplate.watch(key);
stringRedisTemplate.multi();

stringRedisTemplate.opsForValue().set
stringRedisTemplate.exec();

插入的时候开启了事务,并使用了watch乐观锁,和这个有关系吗?