Crate rdb

Source
Expand description

rdb - Parse, analyze and dump RDB files

A RDB file is a binary representation of the in-memory data of Redis. This binary file is sufficient to completely restore Redis’ state.

This library provides the methods to parse and analyze a RDB file and to reformat and dump it in another format such as JSON or RESP, the Redis Serialization.

You can depend on this library via Cargo:

[dependencies]
rdb = "*"

§Basic operation

rdb-rs exposes just one important method: parse. This methods takes care of reading the RDB from a stream, parsing the containted data and calling the provided formatter with already-parsed values.

let file = File::open(&Path::new("dump.rdb")).unwrap();
let reader = BufReader::new(file);
rdb::parse(reader, rdb::formatter::JSON::new(None), rdb::filter::Simple::new());

§Formatter

rdb-rs brings 4 pre-defined formatters, which can be used:

  • PlainFormatter: Just plain output for testing
  • JSONFormatter: JSON-encoded output
  • NilFormatter: Surpresses all output
  • ProtocolFormatter: Formats the data in RESP, the Redis Serialization Protocol

These formatters adhere to the RdbParseFormatter trait and supply a method for each possible datatype or opcode. Its up to the formatter to correctly handle all provided data such as lists, sets, hashes, expires and metadata.

§Command-line

rdb-rs brings a Command Line application as well.

This application will take a RDB file as input and format it in the specified format (JSON by default).

Example:

$ rdb --format json dump.rdb
[{"key":"value"}]
$ rdb --format protocol dump.rdb
*2
$6
SELECT
$1
0
*3
$3
SET
$3
key
$5
value

Re-exports§

pub use decoder::RdbDecoder;
pub use filter::Filter;
pub use filter::Simple;
pub use formatter::Formatter;
pub use formatter::FormatterType;

Modules§

constants
decoder
filter
formatter
types

Structs§

RdbParser
RdbParserBuilder

Functions§

parse