From: Martin Pitt Date: Fri, 16 Sep 2022 09:56:13 +0000 (+0200) Subject: tokio-tutorial-mini-redis: Initial demo X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=commitdiff_plain;h=bd9188aabf12e3071c68d738c614da69473a64d7 tokio-tutorial-mini-redis: Initial demo https://tokio.rs/tokio/tutorial/ --- 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(()) +}