使用 MIGRATE 复制 Redis 数据库中的所有键 [英] Copying all keys in Redis database using MIGRATE
问题描述
是否可以使用 MIGRATE
将所有密钥从一个 Redis 实例复制到另一个远程实例?我试过 COPY
、REPLACE
和 KEYS
没有任何运气.每次我收到 NOKEY
响应时.如果我用一个键使用任何 MIGRATE
命令,它就可以工作.
Is it possible to copy all keys from one Redis instance to another remote instance using MIGRATE
? I've tried COPY
, REPLACE
and KEYS
without any luck. Each time I get a NOKEY
response. If I use any of the MIGRATE
commands with a single key it works.
示例:
MIGRATE my.redis 6379 "*" 0 5000 REPLACE // NOKEY
MIGRATE my.redis 6379 "*" 0 5000 COPY // NOKEY
MIGRATE my.redis 6379 "" 0 5000 KEYS * // NOKEY
MIGRATE my.redis 6379 "" 0 5000 KEYS test // OK
推荐答案
这是对答案的改进@ezain 因为我无法发表评论.该命令使用正确的 redis 语法来处理成批的键,但是 xargs
的参数导致该命令为每个键调用一次,而不是只包含所有键一次(这意味着它将完成所需的时间要多得多).以下在所有情况下都会更快:
This is an improvement on the answer provided by @ezain since I am unable to post comments. The command uses the correct redis syntax for processing batches of keys, but the arguments to xargs
result in the command being called once for every key instead of just once with all the keys included (which means it'll take much more time to complete than is necessary). The following will be much faster in all cases:
redis-cli --raw KEYS '*' |xargs redis-cli 迁移 my.redis 6379 "" 0 5000 KEYS
如果目的地受密码保护:
If the destination is password protected:
redis-cli --raw KEYS '*' |xargs redis-cli MIGRATE my.redis 6379 "" 0 5000 AUTH password-here KEYS
这篇关于使用 MIGRATE 复制 Redis 数据库中的所有键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!