From bd9188aabf12e3071c68d738c614da69473a64d7 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 16 Sep 2022 11:56:13 +0200 Subject: [PATCH] tokio-tutorial-mini-redis: Initial demo https://tokio.rs/tokio/tutorial/ --- tokio-tutorial-mini-redis/Cargo.toml | 10 ++++++++++ tokio-tutorial-mini-redis/src/main.rs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tokio-tutorial-mini-redis/Cargo.toml create mode 100644 tokio-tutorial-mini-redis/src/main.rs diff --git a/tokio-tutorial-mini-redis/Cargo.toml b/tokio-tutorial-mini-redis/Cargo.toml new file mode 100644 index 0000000..eae82db --- /dev/null +++ b/tokio-tutorial-mini-redis/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "tokio-tutorial-mini-redis" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1", features = ["full"] } +mini-redis = "0.4" diff --git a/tokio-tutorial-mini-redis/src/main.rs b/tokio-tutorial-mini-redis/src/main.rs new file mode 100644 index 0000000..a498655 --- /dev/null +++ b/tokio-tutorial-mini-redis/src/main.rs @@ -0,0 +1,17 @@ +use mini_redis::{client, Result}; + +#[tokio::main] +async fn main() -> Result<()> { + // Open a connection to the mini-redis address. + let mut client = client::connect("127.0.0.1:6379").await?; + + // Set the key "hello" with value "world" + client.set("hello", "world".into()).await?; + + // Get key "hello" + let result = client.get("hello").await?; + + println!("got value from the server; result={:?}", result); + + Ok(()) +} -- 2.39.5