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
//! Redis Protocol //! //! Structs and functions for implementing the [Redis protocol](https://redis.io/topics/protocol), built on [nom](https://github.com/Geal/nom) and designed to work easily with [Tokio](https://github.com/tokio-rs/tokio). //! //! //! ## Examples //! //! ```rust //! extern crate redis_protocol; //! extern crate bytes; //! //! use redis_protocol::prelude::*; //! use bytes::BytesMut; //! //! fn main() { //! let frame = Frame::BulkString("foobar".into()); //! let mut buf = BytesMut::new(); //! //! let len = match encode_bytes(&mut buf, &frame) { //! Ok(l) => l, //! Err(e) => panic!("Error encoding frame: {:?}", e) //! }; //! println!("Encoded {} bytes into buffer with contents {:?}", len, buf); //! //! let buf: BytesMut = "*3\r\n$3\r\nFoo\r\n$-1\r\n$3\r\nBar\r\n".into(); //! let (frame, consumed) = match decode_bytes(&buf) { //! Ok((f, c)) => (f, c), //! Err(e) => panic!("Error parsing bytes: {:?}", e) //! }; //! //! if let Some(frame) = frame { //! println!("Parsed frame {:?} and consumed {} bytes", frame, consumed); //! }else{ //! println!("Incomplete frame, parsed {} bytes", consumed); //! } //! //! let key = "foobarbaz"; //! println!("Hash slot for {}: {}", key, redis_keyslot(key)); //! } //! ``` //! //! Or use `decode()` and `encode()` to interact with slices directly. //! #[macro_use] extern crate log; extern crate bytes; extern crate crc16; extern crate pretty_env_logger; #[macro_use] extern crate cookie_factory; #[macro_use] extern crate nom; /// Decoding functions for BytesMut and slices. pub mod decode; /// Encoding functions for BytesMut and slices. pub mod encode; /// Error and Frame types. pub mod types; mod utils; /// Shorthand for `use`'ing `types`, `encode`, `decode`, etc. pub mod prelude { pub use decode::*; pub use encode::*; pub use types::*; pub use utils::redis_keyslot; } pub use utils::{digits_in_number, redis_keyslot, CRLF, NULL, ZEROED_KB};