Skip to content

Commit 3fa7b3b

Browse files
authored
Add async/await example. (redis-rs#261)
Add async/await example.
2 parents a20740c + 5aa07fd commit 3fa7b3b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/async-await.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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")
11+
.arg(&["key2", "bar"])
12+
.query_async(&mut con)
13+
.await?;
14+
15+
let result = redis::cmd("MGET")
16+
.arg(&["key1", "key2"])
17+
.query_async(&mut con)
18+
.await;
19+
assert_eq!(result, Ok(("foo".to_string(), b"bar".to_vec())));
20+
Ok(())
21+
}

0 commit comments

Comments
 (0)