Skip to content

Commit 2115ebf

Browse files
authored
add hello world example (#20)
1 parent 4ac69ae commit 2115ebf

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

examples/hello_world.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1+
//! Hello world server.
2+
//!
3+
//! A simple client that connects to a mini-redis server, sets key "hello" with value "world",
4+
//! and gets it from the server after
5+
//!
6+
//! You can test this out by running:
7+
//!
8+
//! cargo run --bin server
9+
//!
10+
//! And then in another terminal run:
11+
//!
12+
//! cargo run --example hello_world
13+
14+
#![warn(rust_2018_idioms)]
15+
16+
use mini_redis::{client, Result};
17+
118
#[tokio::main]
2-
async fn main() {
3-
unimplemented!();
19+
pub async fn main() -> Result<()> {
20+
// Open a connection to the mini-redis address.
21+
let mut client = client::connect("127.0.0.1:6379").await?;
22+
23+
// Set the key "hello" with value "world"
24+
client.set("hello", "world".into()).await?;
25+
26+
// Get key "hello"
27+
let result = client.get("hello").await?;
28+
29+
println!("got value from the server; success={:?}", result.is_some());
30+
31+
Ok(())
432
}

0 commit comments

Comments
 (0)