Rust wrapper for librdb, the Redis RDB file parser.
Parses RDB dump files and delivers Redis data types (strings, lists, hashes, sets, sorted sets, streams, arrays, and more) through a callback trait, without loading the entire file into memory.
| Crate | Description |
|---|---|
librdb | Safe, high-level wrapper |
librdb-sys | Raw FFI bindings |
[dependencies]
librdb = "0.2"By default, librdb is compiled from the vendored source (git submodule). A C compiler is required.
git clone --recurse-submodules https://github.com/funcpp/rust-librdb
cd rust-librdb
cargo build| Method | How |
|---|---|
| Source build (default) | No extra steps |
| System shared library | --features librdb-sys/dynamic-linking |
| Pre-built static library | Set DEP_LIBRDB_STATIC_ROOT, use --features librdb-sys/static-linking |
use librdb::{Parser,RdbHandlers,KeyInfo,Result};structMyHandler{keys:Vec<String>,}implRdbHandlersforMyHandler{fnhandle_new_key(&mutself,key:&[u8],_info:&KeyInfo) -> Result<()>{self.keys.push(String::from_utf8_lossy(key).into_owned());Ok(())}}fnmain() -> librdb::Result<()>{letmut parser = Parser::new(MyHandler{keys:vec![]})?;
parser.parse_file("dump.rdb")?;let handler = parser.into_handler();println!("{} keys parsed", handler.keys.len());Ok(())}&[u8] callback parameters borrow directly from librdb's internal buffer and
are only valid for the duration of the callback. Clone if you need to retain
the data.
MIT