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

相关推荐
czlczl200209251 小时前
Spring Data Redis
java·redis·spring
he___H2 小时前
Redis高级特性
数据库·redis·缓存
crossaspeed2 小时前
Redis的持久化(八股)
数据库·redis·缓存
1104.北光c°3 小时前
【黑马点评项目笔记 | 登录篇】Redis实现共享Session登录
java·开发语言·数据库·redis·笔记·spring·java-ee
feng一样的男子3 小时前
阿里云的moltbot机器人使用钉钉的Stream流式接入
阿里云·机器人·钉钉
三水不滴5 小时前
Redis 故障转移:哨兵vs集群
数据库·经验分享·redis·缓存·性能优化
yuankoudaodaokou5 小时前
职业院校技能大赛三维扫描设备选购指南:思看科技解决方案解析
阿里云
TracyCoder1235 小时前
Redis 大 Key问题解析与治理
redis
虫小宝5 小时前
查券返利机器人的异步任务调度:Java XXL-Job+Redis实现海量查券请求的分布式任务分发
java·redis·分布式
阿里云大数据AI技术5 小时前
淘宝闪购基于阿里云 EMR Serverless Spark&Paimon 的湖仓实践:超大规模下的特征生产&多维分析双提效
starrocks·阿里云·spark·paimon