【发布时间】:2020-11-08 08:15:52
【问题描述】:
我正在尝试将 redis 作为 web::Data 上下文添加到我的 actix-web rust 应用程序:
extern crate redis;
// std imports
use std::net::SocketAddr;
// external imports
use actix_web::{App, HttpServer};
use redis::Client
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
// connect to redis
let redis_con = Client::open("redis://127.0.0.1:6379")
.unwrap()
.get_connection()
.unwrap();
HttpServer::new(move || App::new().data(redis_con).service(api::get_healthz))
.bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8080)?
.run()
.await
}
我收到以下错误:
the trait bound 'redis::Connection: std::clone::Clone' is not satisfied in '[closure@src/main.rs:48:21: 48:81 redis_con:redis::Connection]'
我已经尝试将其包装为Arc<redis::Connection>,这对于未实现Sync 的redis::Connection 子模块深处的某些类型也不起作用。
在这种情况下我没有看到 Rust 的概念吗? 这是我第一个真正的 Rust 项目之一,所以我可能忽略了一些东西。
【问题讨论】:
标签: redis rust rust-actix actix-web