Things got to be a little strange, the async-API of redis-rs
is built with tokio 0.1, and they can run in a runtime built with async-std! But tokio-postgres which is built with tokio 0.2 is not lucky. When redis-rs has released a new version bases on tokio 0.2, it will also not compatible with async-std
toml
[features]
default = ["tokio-runtime"]
tokio-runtime = ["mobc/tokio-runtime"]
async-std-runtime = ["mobc/async-std-runtime"]
```rust use mobc::futures::channel::mpsc; use mobc::futures::compat::Future01CompatExt; use mobc::futures::prelude::*; use mobc::runtime::DefaultExecutor; use mobc::Error; use mobc::Pool; use mobcredis::redis::{self, RedisError}; use mobcredis::RedisConnectionManager; use std::time::Instant;
const MAX: usize = 5000;
async fn singlerequest(
pool: Pool
let (raw_redis_conn, pong) = redis::cmd("PING")
.query_async::<_, String>(raw_redis_conn)
.compat()
.await?;
conn.set_raw_conn(raw_redis_conn);
assert_eq!("PONG", pong);
sender.send(()).await.unwrap();
Ok(())
}
async fn doredis(sender: mpsc::Sender<()>) -> Result<(), Error
for _ in 0..MAX {
let pool = pool.clone();
let tx = sender.clone();
tokio::spawn(single_request(pool, tx).map(|_| ()));
}
Ok(())
}
async fn main() { envlogger::init(); let mark = Instant::now(); let (tx, mut rx) = mpsc::channel::<()>(MAX); doredis(tx).await.unwrap();
let mut num: usize = 0;
while let Some(_) = rx.next().await {
num += 1;
if num == MAX {
break;
}
}
println!("cost {:?}", mark.elapsed());
}
```