4个版本

0.2.1 2019年11月23日
0.2.0 2019年11月22日
0.1.1 2019年11月23日
0.1.0 2019年11月16日

#2765 in 数据库接口

BSD-3-Clause

50KB
638

redis-ac

redis-trait::Commands trait的异步版本。

Latest version Documentation License Actions Status

获取/设置

use futures::prelude::*;
use redis_ac::Commands;

fn main() {
    let client = redis::Client::open("redis://127.0.0.1/").unwrap();

    let f = client
        .get_async_connection()
        .and_then(|con| {
            con.set("key", "value")
                .and_then(|(con, s): (_, String)| {
                    assert_eq!(s, "OK");
                    con.get("key")
                })
                .map(|(_, s): (_, String)| {
                    assert_eq!(s, "value");
                })
        })
        .map_err(|e| panic!("{}", e));

    tokio::run(f);
}

扫描

use futures::prelude::*;
use redis_ac::Commands;

fn main() {
    let client = redis::Client::open("redis://127.0.0.1/").unwrap();

    let f = client
        .get_shared_async_connection()
        .and_then(|con| {
            con.scan_match("key*")
                .filter_map(|(_, item)| item)
                .for_each(|item: String| {
                    // Here we get items.
                    println!("{}", item);
                    Ok(())
                })
        }).map_err(|e| panic!("{}", e));

    tokio::run(f);
}

依赖

~6MB
~131K SLoC