redis-trib.rb reshard针对有键值的slot迁移失败 Wrong number of arguments for specified sub command

2022-03-29 14:40:46 浏览数 (1)

运行环境:

redis :4.0

redis-trib.rb redis集群管理脚本

ruby: 2.6.3

在执行reshard命令时发现迁移有键值的slot时就会报错Wrong number of arguments for specified sub command,谷歌找到的答案是redis-trib.rb脚本的兼容性问题,需要修改这个脚本migrate部分代码:

代码语言:javascript复制
        # Migrate all the keys from source to target using the MIGRATE command
         while true
             keys = source.r.cluster("getkeysinslot",slot,o[:pipeline])
             break if keys.length == 0
             begin
                 source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:keys,*keys])
             rescue => e
                 if o[:fix] && e.to_s =~ /BUSYKEY/
                     xputs "*** Target key exists. Replacing it for FIX."
                     source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys])
 

将标红部分删除即可,即变成下面:

代码语言:javascript复制
        # Migrate all the keys from source to target using the MIGRATE command
         while true
             keys = source.r.cluster("getkeysinslot",slot,o[:pipeline])
             break if keys.length == 0
             begin
                 source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:keys,*keys])
             rescue => e
                 if o[:fix] && e.to_s =~ /BUSYKEY/
                     xputs "*** Target key exists. Replacing it for FIX."
                     source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys])

参考文章:

https://github.com/antirez/redis/issues/2547

0 人点赞