Crate redis_protocol[−][src]
Redis Protocol
Structs and functions for implementing the Redis protocol, built on nom and designed to work easily with Tokio.
Examples
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.
Modules
decode | Decoding functions for BytesMut and slices. |
encode | Encoding functions for BytesMut and slices. |
prelude | Shorthand for |
types | Error and Frame types. |
Constants
CRLF | Terminating bytes between frames. |
NULL | Byte representation of a |
ZEROED_KB | A pre-defined zeroed out KB of data, used to speed up extending buffers while encoding. |
Functions
digits_in_number | Returns the number of bytes necessary to encode a string representation of |
redis_keyslot | Map a Redis key to its cluster key slot. |