1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
//! 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: //! //! ```ini //! [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. //! //! ```rust,no_run //! # #![allow(unstable)] //! # use std::io::BufReader; //! # use std::fs::File; //! # use std::path::Path; //! let file = File::open(&Path::new("dump.rdb")).unwrap(); //! let reader = BufReader::new(file); //! rdb::parse(reader, rdb::formatter::JSON::new(), 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](http://redis.io/topics/protocol), //! 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: //! //! ```shell,no_compile //! $ rdb --format json dump.rdb //! [{"key":"value"}] //! $ rdb --format protocol dump.rdb //! *2 //! $6 //! SELECT //! $1 //! 0 //! *3 //! $3 //! SET //! $3 //! key //! $5 //! value //! ``` #![feature(io)] #![feature(core)] extern crate lzf; extern crate "rustc-serialize" as serialize; extern crate regex; extern crate byteorder; use std::io::Read; #[doc(hidden)] pub use types::{ ZiplistEntry, Type, /* error and result types */ RdbError, RdbResult, RdbOk, }; pub use parser::RdbParser; use formatter::Formatter; use filter::Filter; mod macros; mod constants; mod helper; pub mod types; pub mod parser; pub mod formatter; pub mod filter; pub fn parse<R: Read, F: Formatter, T: Filter>(input: R, formatter: F, filter: T) -> RdbOk { let mut parser = RdbParser::new(input, formatter, filter); parser.parse() }