Crate redis_protocol[][src]

Expand description

Redis Protocol

Structs and functions for implementing the RESP2 and RESP3 protocol.

Examples


use redis_protocol::resp2::prelude::*;
use 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: BytesMut = "*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));
}

Modules

Types and functions for implementing the RESP2 protocol.

Types and functions for implementing the RESP3 protocol.

Error types and general redis protocol types.

Constants

A pre-defined zeroed out KB of data, used to speed up extending buffers while encoding.

Functions

Returns the number of bytes necessary to encode a string representation of d.

Map a Redis key to its cluster key slot.

Utility function to translate RESP2 frames to RESP3 frames.

Utility function for converting RESP3 frames back to RESP2 frames.