如何使用actix_redis进行获取和发送

时间:2019-02-10 06:59:21

标签: rust rust-actix actix-web actix-redis

这是基于an example的功能。代码可以编译,我可以进行POST,但没有任何内容写入Redis。

fn index(req: &HttpRequest<AppState>) -> Box<Future<Item = HttpResponse, Error = Error>> {
    let redis = req.state().redis_addr.clone();
    let one = redis.send(Command(resp_array!["SET", "mydomain:one", "adfasdfasdf"]));
    let info_set = join_all(vec![one].into_iter());

    info_set
        .map_err(Error::from)
        .and_then(|res: Vec<Result<RespValue, ARError>>|
            // successful operations return "OK", so confirm that all returned as so
            if !res.iter().all(|res| {
                match res {
                    Ok(RespValue::SimpleString(x)) if x == "OK" => true,
                    _ => false
                }
            }) {
                Ok("fadfasfa")
            } else {
                Ok("omg!!!!")
            }
        ).responder();

    req.json()
        .from_err() // convert all errors into `Error`
        .and_then(|val: MyObj| {
            println!("model: {:?}", val);
            Ok(HttpResponse::Ok().json(val)) // <- send response
        })
        .responder()
}

0 个答案:

没有答案