2 releases
0.1.1 | May 20, 2024 |
---|---|
0.1.0 | May 9, 2024 |
#665 in Database interfaces
65 downloads per month
155KB
4K
SLoC
rustdis
Welcome to rustdis, a partial Redis server implementation written in Rust.
This project came to life out of pure curiosity, and because we wanted to learn more about Rust and Redis. So doing this project seemed like a good idea. The primary goal of rustdis is to offer a straightforward and comprehensible implementation, with no optimization techniques to ensure the code remains accessible and easy to understand. As of now, rustdis focuses exclusively on implementing Redis' String data type and its associated methods. You can find more about Redis strings here: Redis Strings.
This server is not production-ready; it is intended purely for educational purposes.
Run
cargo run
Test
cargo test
lib.rs
:
Rustdis is a partial Redis server implementation intended purely for educational purposes.
The primary goal of rustdis is to offer a straightforward and comprehensible implementation, with no optimization techniques to ensure the code remains accessible and easy to understand. As of now, rustdis focuses exclusively on implementing Redis' String data type and its associated methods. You can find more about Redis strings here: Redis Strings.
Architecture
-
server
: Redis server module. Provides a run function that initiates the server, enabling it to begin handling incoming connections from Redis clients. It manages client requests, executes Redis commands, and handles connection lifecycles. -
connection
: The Connection module manages a TCP connection for a Redis client. It separates the TCP stream into readable and writable components to facilitate data consumption and transmission. The server uses this connection module to read data from the TCP connection. -
codec
: This module is responsible for decoding raw TCP byte streams intoFrame
data structures. This is an essential component for translating incoming client requests into meaningful Redis commands. -
frame
: This module defines theFrame
enum, representing different types of Redis protocol messages, and provides parsing and serialization functionalities. It adheres to the RESP (Redis Serialization Protocol) specifications. -
store
: This module provides a simple key-value store for managing Redis string data types. It supports basic operations such as setting, getting, removing, and incrementing values associated with keys.
+--------------------------------------+
| Redis Client |
+-------------------+------------------+
|
| Request (e.g., SET key value)
v
+-------------------+------------------+
| Server |
| (module: server, function: run) |
+-------------------+------------------+
|
| Accept Connection
v
+-------------------+------------------+
| Connection |
| (module: connection, manages TCP |
| connections and streams) |
+-------------------+------------------+
|
| Read Data from TCP Stream
v
+-------------------+------------------+
| Codec |
| (module: codec, function: decode) |
+-------------------+------------------+
|
| Decode Request
v
+-------------------+------------------+
| Frame |
| (module: frame, function: parse) |
+-------------------+------------------+
|
| Parse Command and Data
v
+-------------------+------------------+
| Store |
| (module: store, manages key-value |
| data storage) |
+-------------------+------------------+
|
| Execute Command (e.g., set, get, incr_by)
v
+-------------------+------------------+
| Frame |
| (module: frame, function: serialize)|
+-------------------+------------------+
|
| Encode Response
v
+-------------------+------------------+
| Codec |
| (module: codec, function: encode) |
+-------------------+------------------+
|
| Write Data to TCP Stream
v
+-------------------+------------------+
| Connection |
| (module: connection, manages TCP |
| connections and streams) |
+-------------------+------------------+
|
| Send Response
v
+-------------------+------------------+
| Redis Client |
+--------------------------------------+
Dependencies
~5–12MB
~123K SLoC