Expand description
Bidirectional RESP2/RESP3 protocol implementation.
This crate provides complete RESP (Redis Serialization Protocol) support for both client and server implementations, supporting both RESP2 and RESP3 protocols.
- Values: Parse and encode RESP values (strings, integers, arrays, etc.)
- Requests: Encode commands (client) and parse commands (server)
- Responses: Encode responses (server) and parse responses (client)
§Features
resp3- Enables RESP3 protocol support with additional types:- Boolean (
#t/#f) - Double (
,3.14159) - BigNumber (
(12345678901234567890) - BulkError (
!<len>\r\n<error>) - VerbatimString (
=<len>\r\ntxt:<data>) - Map (
%<len>\r\n<key><val>...) - Set (
~<len>\r\n<elem>...) - Push (
><len>\r\n<elem>...) - Attribute (
|<len>\r\n<attrs>...<value>) - Null (
_\r\n)
- Boolean (
§Example - Client Side
use resp_proto::{Request, Value};
// Encode a GET command
let mut buf = vec![0u8; 1024];
let len = Request::get(b"mykey").encode(&mut buf);
// Parse the response
let response_data = b"+OK\r\n";
let (value, consumed) = Value::parse(response_data).unwrap();§Example - Server Side
use resp_proto::{Command, Value};
// Parse an incoming command
let request_data = b"*2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n";
let (cmd, consumed) = Command::parse(request_data).unwrap();
// Encode a response
let mut buf = vec![0u8; 1024];
let len = Value::bulk_string(b"myvalue").encode(&mut buf);Re-exports§
pub use cluster::NodeInfo;pub use cluster::Redirect;pub use cluster::RedirectKind;pub use cluster::SLOT_COUNT;pub use cluster::SlotMap;pub use cluster::SlotRange;pub use cluster::crc16;pub use cluster::hash_slot;pub use cluster::parse_redirect;pub use streaming::ParseProgress;pub use streaming::STREAMING_THRESHOLD;pub use streaming::SetHeader;pub use streaming::complete_set;pub use streaming::parse_streaming;
Modules§
- cluster
- Redis Cluster protocol building blocks.
- streaming
- Streaming command parser for zero-copy receive optimization.
Structs§
- Parse
Options - Configuration options for RESP value parsing.
- Request
- A request builder for encoding Redis commands.
- SetRequest
- Builder for SET commands with options.
Enums§
- Command
- A parsed Redis command with references to the original buffer.
- Parse
Error - Error type for RESP parsing operations.
- Value
- A RESP protocol value.
Constants§
- DEFAULT_
MAX_ BULK_ STRING_ LEN - Default maximum size of a bulk string in bytes (1MB).
- DEFAULT_
MAX_ COLLECTION_ ELEMENTS - Default maximum number of elements in a collection (array, map, set, etc.).
- DEFAULT_
MAX_ DEPTH - Default maximum nesting depth for recursive structures (arrays, maps, sets, etc.).
- DEFAULT_
MAX_ KEY_ LEN - Default maximum key length in bytes.
- DEFAULT_
MAX_ TOTAL_ ITEMS - Default maximum total items across all collections in a single parse.