Open-Source Wikis

/

Redis

/

Applications

/

redis-check-rdb and redis-check-aof

redis/redis

redis-check-rdb and redis-check-aof

Two static-analysis tools for Redis persistence files. Both are file-system links to redis-server; the binary checks argv[0] and dispatches to a different main().

Active contributors: antirez, Oran Agra, Binbin.

redis-check-rdb

Reads an RDB file, walks every record, and reports any structural error, magic mismatch, version mismatch, checksum failure, or truncated tail.

./redis-check-rdb dump.rdb

The implementation is in src/redis-check-rdb.c and shares the entire RDB parser with the live server (src/rdb.c). That guarantees that if redis-check-rdb says the file is good, the server will be able to load it (and vice versa).

Key callbacks:

  • redis_check_rdb_main(int argc, char **argv, FILE *fp) — the entry point. Called from src/server.c's main() when invoked as redis-check-rdb or as a library function during repair.
  • redisCheckRdbMain — internally drives the parser, prints progress, and tallies type/encoding counts.

There is no repair mode for RDB. If the file is corrupt, the recovery options are: load the previous snapshot, restore from a replica, or replay the AOF.

redis-check-aof

Reads an AOF file or AOF manifest, validates the appended commands, and (with --fix) truncates trailing corruption so the file becomes loadable again.

./redis-check-aof appendonly.aof.manifest
./redis-check-aof appendonly.aof.manifest --fix
./redis-check-aof appendonly.aof              # legacy single-file AOF

The implementation is in src/redis-check-aof.c. Like its RDB sibling, it shares parser code with the server (src/aof.c). It understands:

  • The legacy single-file AOF format used before Redis 7.
  • The Redis 7+ multi-part AOF format: a manifest plus one base RDB plus zero-or-more incremental AOF files.

When run with --fix, the tool prompts for confirmation before truncating, then writes a new file with the verified prefix. The original is left in place under the .bak suffix.

Why these are part of redis-server

Both tools were once separate executables. They were merged into the server binary because:

  1. The parser logic must be identical to the live server's. Sharing the binary makes drift impossible.
  2. Module-defined data types (registered via RedisModule_CreateDataType) appear in RDB. To validate them, the check tool needs to load the same modules the server loads — which is much easier if it is the server.
  3. The startup overhead is negligible; nobody needs redis-check-rdb to be a smaller binary.

The dispatch to the right main() is in src/server.c around line 7975:

if (strstr(exec_name,"redis-check-rdb") != NULL)
    redis_check_rdb_main(argc,argv,NULL);
else if (strstr(exec_name,"redis-check-aof") != NULL)
    redis_check_aof_main(argc,argv);

Output

For RDB the tool prints a summary like:

[offset 0] AUX FIELD redis-ver = '8.0.0'
[offset 0] AUX FIELD redis-bits = '64'
...
[offset NNN] Selecting DB ID 0
[offset NNN] STRING key='foo' value='bar'
...
[info] 12345 keys read
[info] 0 expires
[info] 0 already expired
\o/ RDB looks OK!

For AOF:

Reading AOF section: BASE
... base RDB summary ...
Reading AOF section: INCR
Reading 12345 commands
\o/ AOF looks OK

Or, on failure:

!!! Wrong opcode at offset NNN
The AOF appears to be truncated at offset NNN
You can use redis-check-aof --fix
  • Persistence — the underlying RDB and AOF formats.
  • redis-server — these tools are alternate entry points of the same binary.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

redis-check-rdb and redis-check-aof – Redis wiki | Factory