redis-dump-restore
This is a library for Node.js to dump and restore Redis contents
using DUMP and RESTORE commands.
It issues those commands using the redis npm package. You have to provide
instance of the client yourself. Make sure to set return_buffers
and/or detect_buffers
to true
(see docs) so that we get
Buffer instances from the client.
This is required because otherwise binary data is corrupted. Use 1.0.0+ version of the redis
library - previous
versions have bugs in detect_buffers
handling.
Dependencies
No production-time dependencies. For the list of test-time dependencies and their versions see the package.json
file.
Usage
const redis = require('redis');
const dump = require('@atlassian/redis-dump-restore').dump;
const clientInstance = redis.createClient('localhost', 6379, { detect_buffers: true });
const dumpEx = dump(clientInstance, '*');
dumpEx
.on('data', function (key, data, ttl) {
})
.on('error', function (err) {
})
.on('end', function () {
});
To restore a dump just use the redis
client's restore
command for each saved key. You can do that as a single
transaction if needed using MULTI.
Install instructions
In your project directory run the following command to add this library as a dependency:
npm install redis-dump-restore --save