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有几个中间版本也是可以解决这个问题的,但是最新版本是没问题的,建议升级最新版本

相关推荐
盖伦发发10 小时前
Redis 核心教学: 数据结构, 缓存设计, 分布式锁
java·redis·后端·软件工程
yxlalm10 小时前
对话记忆持久化-Redis热与MySQL冷
android·redis·mysql
夕除1 天前
redis--015
redis
迷茫的大专生1 天前
高可用总结
redis·mysql·nginx·高可用
辉灰笔记1 天前
Redis6.0.10升级迁移至Redis7.4.6(修复CVE‑2025‑49844,业务无需重启)
redis·redis7·漏洞修复·数据库迁移·redis平滑升级·cve-2025-49844
sdm0704271 天前
Linux 中安装 Redis 5
redis
草莓熊Lotso1 天前
【Redis 进阶】主从复制深度解析:从配置落地到 PSYNC 同步原理
linux·开发语言·网络·数据库·redis·缓存·php
聚搜云——JuSouClouD1 天前
在阿里云代理商渠道买轻量服务器,带宽套餐支持自选吗?
服务器·阿里云·云计算
聚搜云——JuSouClouD1 天前
2026找阿里云代理商采购GPU服务器,有没有额外折扣?
服务器·阿里云·云计算
运维栈记1 天前
使用 MinIO Client (mc) 将自建 MinIO 数据备份至阿里云 OSS
运维·阿里云