Skip to main content

Crate resp_proto

Crate resp_proto 

Source
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)

§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§

ParseOptions
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.
ParseError
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.