Crate redis_protocol[][src]

Redis Protocol

Structs and functions for implementing the Redis protocol, built on nom and designed to work easily with Tokio.

Examples

extern crate redis_protocol;
extern crate bytes;

use redis_protocol::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_bytes(&buf) {
    Ok((f, c)) => (f, c),
    Err(e) => panic!("Error parsing bytes: {:?}", e)
  };

  if let Some(frame) = frame {
    println!("Parsed frame {:?} and consumed {} bytes", frame, consumed);
  }else{
    println!("Incomplete frame, parsed {} bytes", consumed);
  }

  let key = "foobarbaz";
  println!("Hash slot for {}: {}", key, redis_keyslot(key));
}

Or use decode() and encode() to interact with slices directly.

Modules

decode
encode
prelude
types

Functions

redis_keyslot

Map a Redis key to its cluster key slot.