Skip to content

Commit ecf1eb4

Browse files
carllercheDarksonn
andauthored
More comments and tweak details (#33)
Co-authored-by: Alice Ryhl <[email protected]>
1 parent 5752d1e commit ecf1eb4

File tree

15 files changed

+613
-201
lines changed

15 files changed

+613
-201
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ application.
1010
**Disclaimer** Don't even think about trying to use this in production... just
1111
don't.
1212

13+
## Why Redis
14+
15+
The primary goal of this project is teaching Tokio. Doing this requires a
16+
project with a wide range of features with a focus on implementation simplicity.
17+
Redis, an in-memory database, provides a wide range of features and uses a
18+
simple wire protocol. The wide range of features allows demonstrating many Tokio
19+
patterns in a "real world" context.
20+
21+
The Redis wire protocol documentation can be found [here](https://redis.io/topics/protocol).
22+
23+
The set of commands Redis provides can be found
24+
[here](https://redis.io/commands).
25+
26+
1327
## Running
1428

1529
The repository provides a server, client library, and some client executables
@@ -117,6 +131,12 @@ the server to update the active subscriptions.
117131
The server uses a `std::sync::Mutex` and **not** a Tokio mutex to synchronize
118132
access to shared state. See [`db.rs`](src/db.rs) for more details.
119133

134+
### Testing asynchronous code that relies on time
135+
136+
In [`tests/server.rs`](tests/server.rs), there are tests for key expiration.
137+
These tests depend on time passing. In order to make the tests deterministic,
138+
time is mocked out using Tokio's testing utilities.
139+
120140
## Contributing
121141

122142
Contributions to `mini-redis` are welcome. Keep in mind, the goal of the project
@@ -128,6 +148,9 @@ demonstrate a new pattern.
128148

129149
Contributions should come with extensive comments targetted to new Tokio users.
130150

151+
Contributions that only focus on clarifying and improving comments are very
152+
welcome.
153+
131154
## FAQ
132155

133156
#### Should I use this in production?

examples/sub.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub async fn main() -> Result<()> {
2929
let mut subscriber = client.subscribe(vec!["foo".into()]).await?;
3030

3131
// await messages on channel foo
32-
let msg = subscriber.next_message().await? ;
33-
println!("got message from the channel: {}; message = {:?}", msg.channel, msg.content);
34-
32+
if let Some(msg) = subscriber.next_message().await? {
33+
println!("got message from the channel: {}; message = {:?}", msg.channel, msg.content);
34+
}
3535

3636
Ok(())
3737
}

src/bin/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ async fn main() -> mini_redis::Result<()> {
6363
// Establish a connection
6464
let mut client = client::connect(&addr).await?;
6565

66+
// Process the requested command
6667
match cli.command {
6768
Command::Get { key } => {
6869
if let Some(value) = client.get(&key).await? {

src/bin/server.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! mini-redis server.
2+
//!
3+
//! This file is the entry point for the server implemented in the library. It
4+
//! performs command line parsing and passes the arguments on to
5+
//! `mini_redis::server`.
6+
//!
7+
//! The `clap` crate is used for parsing arguments.
8+
19
use mini_redis::{server, DEFAULT_PORT};
210

311
use clap::Clap;

0 commit comments

Comments
 (0)