Crate tinyresp

source ·
Expand description

A simple parser for the RESP protocol (REdis Serialization Protocol).

For an overview of the procol check out the official Redis SErialization Protocol (RESP) documentation

This library is written using nom and therefore uses an incremental parsing approach. This means that using the parse method will return a Result containing a tuple with 2 elements:

  • The remaining input (which can be an empty string if the message was fully parsed)
  • The parsed value (if the message was fully parsed)

§Example

use tinyresp::{parse_value, Value};

let message = "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n";
let (remaining_input, value) = parse_value(message).unwrap();
assert_eq!(remaining_input, "");
assert_eq!(value, Value::Array(vec![
    Value::BulkString("hello"),
    Value::BulkString("world")
]));

Enums§

  • Represents an error that can occur when trying to convert a Value to a HashMap
  • Represents a RESP value

Functions§

  • A convenience function that parses a complete RESP message and returns the parsed value only. It internally uses parse_message and returns the parsed value directly (or an error). This function will return an error if you have any leftover input because parse_message makes sure you consume all the input. If you want to use an incremental approach, you are recommended to use parse_value instead.
  • Parses a complete RESP message using an incremental parsing approach. This parser makes sure that the input is fully consumed and returns an error if there is any leftover input.
  • Parses a RESP value using an incremental parsing approach. This means that the parser will return a Result containing a tuple with 2 elements: