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

相关推荐
我不会起名字3226 小时前
Redis 从 0 到 1(十七):订单 30 分钟不支付自动关闭——ZSet 延迟队列 Go 实现
redis·go·延迟队列·zset·订单
利威尔xu8 小时前
Go IM 源码实战(13):30 个会话只有 2 个红点,未读数错在三条路径
redis·后端·微服务·面试·golang
will_net10 小时前
Redis集群部署+Redis 链接地址放入Aollo +c#项目接入Redis
redis·c#·bootstrap
用户69190268133912 小时前
Redis 1:简述Redis概念与Agent的联系
redis·后端·设计
小南家的青蛙13 小时前
华为云DCS全形态原生Redis命令兼容性测试方案
redis·华为云·兼容性·兼容性测试·dcs
xiaoqiMikko13 小时前
Redis 实战(三):持久化出错 —— fork 失败、磁盘写满、AOF 膨胀与损坏,逐个复现(6.2.4)
redis·后端
IT规划师14 小时前
面试中被嘲笑Token放在redis里,该如何应对?
redis·面试
我不会起名字32215 小时前
Redis 从 0 到 1(十九):JWT 还是 Redis Session?登录态存储的 Go 实现
redis·go·jwt·session·登录态