This tutorial will take you step by step through the process of building a Redis client and server. We will start with the basics of asynchronous programming with Rust and build up from there. We will implement a subset of Redis commands but will get a comprehensive tour of Tokio.
The project that you will build in this tutorial is available as Mini-Redis on GitHub. Mini-Redis is designed with the primary goal of learning Tokio, and is therefore very well commented, but this also means that Mini-Redis is missing some features you would want in a real Redis library. You can find production-ready Redis libraries on crates.io.
We will use Mini-Redis directly in the tutorial. This allows us to use parts of Mini-Redis in the tutorial before we implement them later in the tutorial.
While not required, some experience with writing networking code using the Rust standard library or another language can be helpful.
No pre-existing knowledge of Redis is required.
This tutorial requires a minimum of Rust version
1.45.0, but the most
recent stable version of Rust is recommended.
To check that Rust is installed on your computer, run the following:
$ rustc --version
You should see output like
rustc 1.46.0 (04488afe3 2020-08-24).
Next, install the Mini-Redis server. This will be used to test our client as we build it.
$ cargo install mini-redis
Make sure that it was successfully installed by starting the server:
Then, in a separate terminal window, try to get the key
$ mini-redis-cli get foo
You should see
That's it, everything is ready to go. Go to the next page to write your first asynchronous Rust application.