]> piware.de Git - learn-rust.git/blobdiff - tokio-tutorial-mini-redis/examples/hello-redis.rs
tokio-tutorial-mini-redis: Initial protocol
[learn-rust.git] / tokio-tutorial-mini-redis / examples / hello-redis.rs
diff --git a/tokio-tutorial-mini-redis/examples/hello-redis.rs b/tokio-tutorial-mini-redis/examples/hello-redis.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(())
+}