Skip to main content

Crate memcache_proto

Crate memcache_proto 

Source
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 support
  • binary: Binary protocol support
  • full: 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.
ParseOptions
Configuration options for command parsing.
ReplaceRequest
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.
ParseError
Error type for Memcache parsing operations.
ParseProgress
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.