tokio-tutorial-mini-redis: Initial demo
authorMartin Pitt <martin@piware.de>
Fri, 16 Sep 2022 09:56:13 +0000 (11:56 +0200)
committerMartin Pitt <martin@piware.de>
Fri, 16 Sep 2022 09:56:13 +0000 (11:56 +0200)
https://tokio.rs/tokio/tutorial/

tokio-tutorial-mini-redis/Cargo.toml [new file with mode: 0644]
tokio-tutorial-mini-redis/src/main.rs [new file with mode: 0644]

diff --git a/tokio-tutorial-mini-redis/Cargo.toml b/tokio-tutorial-mini-redis/Cargo.toml
new file mode 100644 (file)
index 0000000..eae82db
--- /dev/null
@@ -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 (file)
index 0000000..a498655
--- /dev/null
@@ -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(())
+}