Skip to content

Commit 9dd0bde

Browse files
committed
Add async/await example.
1 parent e24d1f3 commit 9dd0bde

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

examples/async-await.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use redis::AsyncCommands;
2+
3+
#[tokio::main]
4+
async fn main() -> redis::RedisResult<()> {
5+
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
6+
let mut con = client.get_async_connection().await?;
7+
8+
let () = con.set("key1", b"foo").await?;
9+
10+
let () = redis::cmd("SET").arg(&["key2", "bar"]).query_async(&mut con).await?;
11+
12+
let result = redis::cmd("MGET")
13+
.arg(&["key1", "key2"])
14+
.query_async(&mut con)
15+
.await;
16+
assert_eq!(result, Ok(("foo".to_string(), b"bar".to_vec())));
17+
Ok(())
18+
}

0 commit comments

Comments
 (0)