Expand description
Bidirectional Memcache protocol implementation.
This crate provides complete Memcache protocol support for both client and server implementations. Both ASCII and binary protocols are supported.
§Features
ascii(default): ASCII text protocol supportbinary: Binary protocol supportfull: Both ASCII and binary protocols
§ASCII Protocol
The ASCII protocol is text-based and human-readable. It’s easier to debug but has more parsing overhead.
§Example - Client Side
use memcache_proto::{Request, Response};
// 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"VALUE mykey 0 5\r\nhello\r\nEND\r\n";
let (response, consumed) = Response::parse(response_data).unwrap();§Example - Server Side
use memcache_proto::{Command, Response};
// Parse an incoming command
let request_data = b"get mykey\r\n";
let (cmd, consumed) = Command::parse(request_data).unwrap();
// Encode a response
let mut buf = vec![0u8; 1024];
let len = Response::stored().encode(&mut buf);§Binary Protocol
The binary protocol uses fixed 24-byte headers and is more efficient for
high-throughput scenarios. Enable with the binary feature.
ⓘ
use memcache_proto::binary::{BinaryRequest, BinaryResponse, Opcode};
// Encode a GET request
let mut buf = [0u8; 256];
let len = BinaryRequest::encode_get(&mut buf, b"mykey", 1);Structs§
- AddRequest
- Builder for ADD requests with optional flags and exptime.
- Parse
Options - Configuration options for command parsing.
- Replace
Request - Builder for REPLACE requests with optional flags and exptime.
- SetHeader
- Parsed SET command header (before value data).
- Value
- A single value from a GET response.
Enums§
- Command
- A parsed Memcache command with references to the original buffer.
- Parse
Error - Error type for Memcache parsing operations.
- Parse
Progress - Result of incremental parsing.
- Request
- A request builder for encoding Memcache commands.
- Response
- A parsed Memcache response.
Constants§
- DEFAULT_
MAX_ KEYS - Default maximum number of keys in a multi-GET command (batch size).
- DEFAULT_
MAX_ KEY_ LEN - Default maximum key size in bytes (memcached default is 250)
- DEFAULT_
MAX_ VALUE_ LEN - Default maximum value size in bytes (memcached default is 1MB)
- STREAMING_
THRESHOLD - Threshold for streaming large values (64KB).
Functions§
- complete_
set - Complete a SET command after receiving the full value.
- parse_
streaming - Parse a memcache command with streaming support for large values.