Last active
November 1, 2017 09:27
-
-
Save jinuljt/002e60fc502f2477673f82856a5ecae7 to your computer and use it in GitHub Desktop.
transfer redis database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
from="redis-cli -n 1" | |
to="redis-cli -n 5" | |
while read key; | |
do | |
$to del $key | |
$from --raw dump $key | head -c-1 | $to -x restore $key 0 | |
done < <($from --scan) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
redis 不提供 dump/restore 这样的命令行工具来迁移整个数据库。所以使用 redis-cli 的 dump/restore 命令来一次性迁移所有key。
因为在某些情况(例如我所使用的阿里云redis)无法替换redis服务器的 rdb 文件。