As a preface, read this for the motivation and concept behind Redis protocol streams (as usual, Redis documentation is amazingly well written and a joy to read).
redis-rdb-tools is a utility that creates a protocol stream from a .rdb
file. However, the original repo has a Unicode decoding bug that prevents it from working properly. Thankfully, someone forked it and patched it, and I can confirm that the patch works for me. To install (make sure you’re on Python 2.x, not 3.x):
$ pip install git+https://github.com/lesandr/redis-rdb-tools@1f7bcf366073adf5510ad18f1efe0bf46ae5e0c1
(I’m installing the specific patch commit because it’s a fork and who knows what’ll happen to it in the future.)
Then, to import the file, just a simple one-liner:
$ rdb --command protocol /path/to/dump.rdb | redis-cli --pipe
If successful, you’ll see something like:
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 4341259
as well as this in your Redis server logs:
95086:M 01 Mar 21:53:42.071 * 10000 changes in 60 seconds. Saving...
95086:M 01 Mar 21:53:42.072 * Background saving started by pid 98223
98223:C 01 Mar 21:53:44.277 * DB saved on disk
Notes:
- Make sure you already have a Redis server running. The
--pipe
flag is only available for Redis 2.6 onwards. - If you want to inspect the protocol stream visually before importing, you can leave out the piping to
redis-cli
and it will pipe the stream toSTDOUT
(or you could pipe it to a text file).
The alternative way to import is to copy the .rdb
file to the location specified in your redis.conf
(or modify redis.conf
to point to your .rdb
file). However, I think using protocol streams is a cooler solution. 😎