A very simple implementation of a Redis like server in Rust - for learning purposes (specially the Tokio stack).
- Try to never use
unwrap()
in production, if you so require, try usingexpect()
. - In Tokio, a task is the equivalent of terms like green thread, fiber, coroutine, etc.
- Rust
async fn
always returns an anonymousimpl Future
type. - Rust async is lazy in nature. Unless
.await
is called, aFuture
will never be executed. - Use
type
aliases to clarify and shorten; long types. - Sharding is a very basic but awesome concept - allows you to split your data storage into multiple parts (or shards) to reduce contentions for both reads and writes. Check lib.rs for a basic implementation.
- Use
tokio::sync::oneshot
instead of callbacks for passing messages around and communicating among different tasks. - Pair
tokio::sync::mpsc
with tasks to create manager tasks that manage communication with services such as db, api clients, etc. See client.rs for an example.
Run the server in one terminal.
cargo run --bin server
Run the client in another terminal.
cargo run --bin client