hello-redis.rs (809B)
1 use mini_redis::{Result, client}; 2 3 #[tokio::main] 4 async fn main() -> Result<()> { 5 // Open a connection to the mini-redis address 6 // 7 // connect function asynchronously establishes a TCP connection with the 8 // specified remote address. Once the connection is established, a client 9 // handle is returned. Even though the operation is performed asynchronously, 10 // the code we write looks synchronous. The only indication that the operation 11 // is asynchronous is the .await operator. 12 let mut client = client::connect("127.0.0.1:6379").await?; 13 14 // Set the key "hello" with value "world" 15 client.set("hello", "world".into()).await?; 16 17 // Get key "hello" 18 let result = client.get("hello").await?; 19 20 print!("got value from the server; result={result:?}"); 21 22 Ok(()) 23 }