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 fnalways returns an anonymousimpl Futuretype. - Rust async is lazy in nature. Unless
.awaitis called, aFuturewill never be executed. - Use
typealiases 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::oneshotinstead of callbacks for passing messages around and communicating among different tasks. - Pair
tokio::sync::mpscwith 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 serverRun the client in another terminal.
cargo run --bin client