Ultralight tool for exporting/importing a redis database.
The current version of redport, v0.1.2, is considered to be highly experimental. Please use it with extreme caution. This status will hopefully change as I use the tool repeatedly and with growing confidence.
redport is meant to be used as a node.js command-line tool. To install: npm install redport
.
redport's only dependency is the redis
module.
All operations are done against a local redis running on the default port (6379).
redport only can export/import one database at a time (redis has 16 databases, numbered from 0 to 15).
Important: When importing to a database, it will completely delete it (with the flushdb
command).
redport will prompt the user for confirmation before proceeding to perform an import or export operation.
To export database #0 to a file named output.json
:
node redport 0 output
To import a file output.json
(previously generated by redport) into database #15
node redport output 15
When exporting, redport uses scan
to incrementally iterate redis keys, so it can be used against large databases in production environments without fear of blocking the database.
When importing, redport uses the readline
module to incrementally read the input file, so importing from large files should be possible even with limited available memory.
However, please remember that redport is experimental, for the time being. Please don't rely on it for handling production data, especially if you don't have backups.
The complete source code is contained in redport.js
. It is about 130 lines long.
Annotated source code will be forthcoming when the library stabilizes.
redport is written by Federico Pereiro (fpereiro@gmail.com) and released into the public domain.