Redis Database Dump Tool

0.1.10 · abandoned · verified Wed Apr 22

The `redis-dump` package provides a utility for exporting data from a Redis database, offering output in two primary formats: a series of Redis commands suitable for direct re-import via `redis-cli`, or a structured JSON representation for programmatic processing. The current stable version, `0.1.10`, was last published in March 2014, indicating that the project is no longer actively maintained. Its core functionality enables users to backup, migrate, or inspect Redis data, differentiating itself by supporting both a command-line interface and a programmatic API for Node.js applications. Due to its age, it predates modern JavaScript module systems and may not be compatible with newer Redis features or Node.js versions, and has an effectively non-existent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `redis-dump` programmatically by spawning it as a child process to export Redis data in both JSON and Redis command formats, first populating some example data using a modern Redis client.

const redis = require('redis');
const { spawn } = require('child_process');

async function runDump() {
    const client = redis.createClient({
        url: process.env.REDIS_URL || `redis://${process.env.REDIS_HOST || '127.0.0.1'}:${process.env.REDIS_PORT || '6379'}`,
        password: process.env.REDIS_PASSWORD || ''
    });

    client.on('error', (err) => {
        console.error('Redis Client Error', err);
    });

    try {
        await client.connect();

        // Populate some dummy data for demonstration
        await client.del('mydb:numberlist', 'mydb:numberset', 'mydb:numvisits');
        await client.rPush('mydb:numberlist', 'one', 'two', 'three');
        await client.sAdd('mydb:numberset', 'one', 'two', 'three');
        await client.set('mydb:numvisits', '34');
        console.log('Dummy data populated in Redis.');

        // Define common connection arguments for redis-dump CLI
        const commonDumpArgs = [
            '-h', process.env.REDIS_HOST || '127.0.0.1',
            '-p', process.env.REDIS_PORT || '6379',
            '-a', process.env.REDIS_PASSWORD || '',
            '-f', 'mydb:*'
        ];

        // Dump as JSON
        console.log('\n--- Dumping as JSON ---');
        const jsonDumpProcess = spawn('redis-dump', [...commonDumpArgs, '--json', '--pretty']);

        let jsonOutput = '';
        jsonDumpProcess.stdout.on('data', (data) => { jsonOutput += data.toString(); });
        jsonDumpProcess.stderr.on('data', (data) => { console.error(`stderr (JSON dump): ${data}`); });
        await new Promise((resolve, reject) => {
            jsonDumpProcess.on('close', (code) => {
                if (code === 0) { console.log('JSON Dump Output:\n', jsonOutput); resolve(); }
                else { reject(new Error(`redis-dump JSON process exited with code ${code}`)); }
            });
        });

        // Dump as Redis commands
        console.log('\n--- Dumping as Redis Commands ---');
        const commandDumpProcess = spawn('redis-dump', commonDumpArgs);

        let commandOutput = '';
        commandDumpProcess.stdout.on('data', (data) => { commandOutput += data.toString(); });
        commandDumpProcess.stderr.on('data', (data) => { console.error(`stderr (Command dump): ${data}`); });
        await new Promise((resolve, reject) => {
            commandDumpProcess.on('close', (code) => {
                if (code === 0) { console.log('Command Dump Output:\n', commandOutput); resolve(); }
                else { reject(new Error(`redis-dump Command process exited with code ${code}`)); }
            });
        });

    } catch (error) {
        console.error('An error occurred:', error);
    } finally {
        await client.disconnect();
        console.log('Redis client disconnected.');
    }
}

runDump();

view raw JSON →