2 stable releases
4.2.0 | Jan 31, 2023 |
---|---|
4.1.0 | Mar 28, 2022 |
#2557 in Parser implementations
39 downloads per month
Used in embedded-redis
325KB
9K
SLoC
Fork
NOTE: This fork was exclusivly created for the following upstream PR: https://github.com/aembke/redis-protocol.rs/pull/21
This crate will get deleted once the upstream PR has been merged and published!
lib.rs
:
Redis Protocol
Structs and functions for implementing the RESP2 and RESP3 protocol.
Examples
use redis_protocol::resp2::prelude::*;
use bytes::{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: Bytes = "*3\r\n$3\r\nFoo\r\n$-1\r\n$3\r\nBar\r\n".into();
let (frame, consumed) = match decode(&buf) {
Ok(Some((f, c))) => (f, c),
Ok(None) => panic!("Incomplete frame."),
Err(e) => panic!("Error parsing bytes: {:?}", e)
};
println!("Parsed frame {:?} and consumed {} bytes", frame, consumed);
let key = "foobarbaz";
println!("Hash slot for {}: {}", key, redis_keyslot(key.as_bytes()));
}
Note: if callers are not using the index-map
feature then substitute std::collections::HashMap
for any IndexMap
types in these docs. rustdoc
doesn't have a great way to show type substitutions based on feature flags.
Dependencies
~1.2–2.1MB
~37K SLoC