stream_resp
StreamRESP is a RESP (Redis Serialization Protocol) parser fully compliant with RESP3, implemented using a finite state machine (FSM) approach. Designed for streaming scenarios.
- Full RESP3 support: All RESP3 types are supported.
- Optional explicit positive integer sign: Enable the
explicit-positive-signfeature to support parsing integers with an explicit+sign (e.g.,:+123\r\n).
Documentation: DeepWiki
Installation
To use stream_resp in your project, add the following to your Cargo.toml:
[]
= "1"
Features
Enabling jemalloc
If you want to enable jemalloc for better memory allocation performance, you can enable the jemalloc feature in your Cargo.toml:
[]
= { = "1", = ["jemalloc"] }
Enabling Explicit Positive Integer Sign (+)
By default, the parser strictly adheres to the RESP specification for integers (:<number>\r\n). However, some clients or protocols might use an explicit plus sign (:+<number>\r\n). To enable parsing of integers with an explicit +, enable the integer-plus-sign feature:
[]
= { = "1", = ["explicit-positive-sign"] }
You can also enable multiple features:
[]
= { = "1", = ["jemalloc", "explicit-positive-sign"] }
Usage
Here are some examples demonstrating how to use the stream_resp parser.
Example 1: Basic Usages
let value = Array;
assert_eq!;
Example 1: Streaming RESP Messages over TCP
use ;
use ;
use ;
use RespValue;
Example 2: Parsing Complete RESP Messages
use Cow;
use ;
use RespValue;
Example 3: Parsing Incomplete RESP Messages in Chunks
use Cow;
use ;
use RespValue;
Benchmarks
The project includes performance benchmarks for the RESP parser. To run the benchmarks:
# Run all benchmarks
# Run a specific benchmark group
# Run a specific benchmark test
The benchmark results will be displayed in your terminal. Detailed HTML reports will be generated in the target/criterion directory, which you can open in a web browser to see more detailed performance information.
Viewing Benchmark Results
After running the benchmarks, you can find detailed reports in:
target/criterion/report/index.html
The benchmarks measure parsing performance across various RESP data types and scenarios including:
- Simple strings, errors, integers
- Bulk strings (empty, null, large)
- Arrays (simple, nested, large)
- Real-world commands
- Batched commands
- Chunked parsing
Benchmark results will be displayed in the terminal and detailed HTML reports are generated in the
target/criterion directory.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.