Redisson3.14.1及之后连接阿里云redis代理模式,使用分布式锁:ERR unknown command ‘WAIT‘

文章目录

一、问题背景

1、问题原因

阿里云Redis分直连和代理模式,其中代理模式是不支持WAIT命令的。

目前尝试使用redisson实现分布式锁的时候出现无法执行WAIT命令(实际分布式锁命令是执行成功的,只是3.14.1及之后的redisson版本会报未知WAIT命令的错误)

Redisson 很早就会附加 WAIT 命令,只是从 3.14.1 开始才关注 WAIT 命令的执行结果。

java 复制代码
Exception in thread "main" org.redisson.client.RedisException: ERR unknown command 'WAIT'. channel: [id: 0xf842ee1d, L:/192.168.1.20:52123 - R:/192.168.1.10:6379] command: (WAIT), params: [1, 1000]
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:343)
	at org.redisson.client.handler.CommandDecoder.decodeCommandBatch(CommandDecoder.java:247)
	at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:189)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:117)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:102)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:510)
	at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:750)

阿里云官方强调【暂不支持通过集群架构的Proxy节点(代理模式)执行WAIT命令,如有需要,您可以通过集群架构的直连地址执行WAIT命令】),从而导致报错。源码层面的原因在于当进行加锁或者解锁操作时,redisson会判断当前集群的redis节点数是否大于0来给命令数组对象增加WAIT命令,这个是所有版本的redisson都有。

2、阿里云对Redisson的支持

阿里云对Redisson的支持态度很模糊,表示不会特意去适配Redisson。

二、解决方案

1、继续使用Redisson3.14.0版本

不去关注 WAIT 命令的执行结果,相当于没有 WAIT 命令。

Redisson3.14.0版本虽然也使用了WAIT命令,但是没有关注其结果,所以不会报错。

2、阿里云redis改为直连模式

阿里云redis跳过代理,改为直连模式。

相当于直接连接redis。

3、升级Redisson版本到 3.47.0+

看这个Issue:https://github.com/redisson/redisson/issues/6716

实测确实可以解决。

Redisson有几个中间版本也是可以解决这个问题的,但是最新版本是没问题的,建议升级最新版本

相关推荐
爱吃鱼的喵️26 分钟前
华为云腾讯云阿里云哪个好:华为云、腾讯云、阿里云对比分析
阿里云·华为云·腾讯云
聚美智数1 小时前
聚美智数×阿里云百炼OneKeyMCP:一个APIKey,连接海量Agent生态
阿里云·云计算
永栀哇5 小时前
RT-Thread studio STM32F407+RW007模块+物联网软件包-阿里云-onenet云平台
阿里云·wifi·onenet·rtthread-stm32·物联网软件包
一嘴一个橘子5 小时前
Redis List 数据类型
redis
小园子的小菜6 小时前
Redis 核心原理深度解析:从数据结构、IO 模型到持久化机制
数据库·redis·缓存
BullSmall21 小时前
Another Redis Desktop Manager(ARDM)下载指南
数据库·redis·缓存
nvd111 天前
ArgoCD 双层轮询深入拆解:从 redis-app.yaml 注册到缓存重建的完整链路
redis·缓存·argocd
xiaoxiangsiyan1 天前
LNMP + Redis Sentinel 高可用架构部署手册(续)
运维·网络·数据库·redis·缓存·架构·sentinel
CodeHackerBhx1 天前
Spring Boot 4 防重复提交:从接口幂等到 Redis 分布式锁的完整实践
java·数据库·spring boot·redis·分布式