#redis #serialization #parser #resp #protocols #nom #tiny

tinyresp

A tiny Rust library implementing the Redis Serialization Protocol (RESP)

4 releases (2 breaking)

0.2.1 Feb 29, 2024
0.2.0 Feb 29, 2024
0.1.0 Feb 28, 2024
0.0.1 Jan 29, 2024

#861 in Parser implementations

Download history 3/week @ 2024-07-27 3/week @ 2024-09-28

97 downloads per month

MIT license

38KB
830 lines

tinyresp

Build Status codecov Crates.io docs.rs

A tiny Rust library implementing the Redis Serialization Protocol (RESP)

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")
]));

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

License

Licensed under MIT License. © Luciano Mammino, Roberto Gambuzzi.

Dependencies

~1–1.7MB
~35K SLoC