Skip to content

Instantly share code, notes, and snippets.

@jinuljt
Last active November 1, 2017 09:27
Show Gist options
  • Save jinuljt/002e60fc502f2477673f82856a5ecae7 to your computer and use it in GitHub Desktop.
Save jinuljt/002e60fc502f2477673f82856a5ecae7 to your computer and use it in GitHub Desktop.
transfer redis database
#!/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)
@jinuljt
Copy link
Author

jinuljt commented Nov 1, 2017

redis 不提供 dump/restore 这样的命令行工具来迁移整个数据库。所以使用 redis-cli 的 dump/restore 命令来一次性迁移所有key。
因为在某些情况(例如我所使用的阿里云redis)无法替换redis服务器的 rdb 文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment