Databases 6 min read

Add Online AOF and RDB Loading to Redis 3.0.7 Without Restart

This article explains how to modify Redis 3.0.7 by adding LOADAOF and LOADRDB commands that enable online loading of AOF and RDB files, eliminating the need to restart the server even in master‑slave replication scenarios.

dbaplus Community
dbaplus Community
dbaplus Community
Add Online AOF and RDB Loading to Redis 3.0.7 Without Restart

Introduction

When loading data into Redis, the traditional approach requires restarting the Redis service, which is inconvenient especially in a master‑slave replication setup. This article presents a modification to Redis 3.0.7 that adds two new commands, LOADAOF and LOADRDB, enabling online loading of AOF and RDB files without a restart.

Design and Implementation

The implementation adds two commands to the Redis command table and corresponding functions in the source code.

LOADAOF Command

void loadaofCommand(RedisClient *c) {
    if (server.rdb_child_pid != -1) {
        addReplyError(c,"Background save already in progress");
    } else if (server.aof_child_pid != -1) {
        addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress");
    } else if (c->argc != 2){
        addReply(c,shared.syntaxerr);
        return;
    } else if (loadAppendOnlyFile(c->argv[1]->ptr) == REDIS_OK) {
        addReplyStatus(c,"online loadaof started,Do not repeat!!!");
    } else {
        addReply(c,shared.err);
    }
}

LOADRDB Command

void loadrdbCommand(RedisClient *c) {
    if (server.rdb_child_pid != -1) {
        addReplyError(c,"Background save already in progress");
    } else if (server.aof_child_pid != -1) {
        addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress");
    } else if (c->argc != 2){
        addReply(c,shared.syntaxerr);
        return;
    } else if (rdbLoad(c->argv[1]->ptr) == REDIS_OK) {
        addReplyStatus(c,"online loadrdb started,Do not repeat !!!");
    } else {
        addReply(c,shared.err);
    }
}

The new commands are registered in src/Redis.c by adding entries to RedisCommandTable:

{"loadaof",loadaofCommand,2,"ar",0,NULL,0,0,0,0,0},
{"loadrdb",loadrdbCommand,2,"ar",0,NULL,0,0,0,0,0},

Function prototypes are added to src/Redis.h:

void loadrdbCommand(RedisClient *c);
void loadaofCommand(RedisClient *c);

Help entries are added in src/help.h to document the new commands.

Compilation

cd Redis-3.0.7
make && make PREFIX=/usr/local/Redis30 install

Test Results

Test result
Test result

The test demonstrates that data can be loaded into a running Redis instance without restarting the server.

Use Cases

Importing data into a test Redis instance for analysis.

Recovering data after accidental deletion, especially in Sentinel‑plus‑master‑slave architectures.

Precautions

When the master loads an AOF or RDB file online, the replica must have the same file; otherwise the replica will exit with an error.

Do not execute the same load command repeatedly on the same file, as it may cause the master or replica to crash.

The current implementation is a proof of concept and may require further robustness improvements.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backend DevelopmentRedisAOFRDBOnline Loading
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.