18 releases

0.8.2 Nov 20, 2023
0.8.0 Jan 22, 2023
0.7.0 Jan 13, 2021
0.5.4 Nov 14, 2020
0.3.0 Nov 30, 2019

#1316 in Database interfaces

Download history 1219/week @ 2024-03-14 1752/week @ 2024-03-21 1356/week @ 2024-03-28 1602/week @ 2024-04-04 1743/week @ 2024-04-11 1795/week @ 2024-04-18 1457/week @ 2024-04-25 1357/week @ 2024-05-02 1568/week @ 2024-05-09 1689/week @ 2024-05-16 2407/week @ 2024-05-23 2008/week @ 2024-05-30 2309/week @ 2024-06-06 3012/week @ 2024-06-13 2532/week @ 2024-06-20 2025/week @ 2024-06-27

10,270 downloads per month
Used in 9 crates (5 directly)

MIT/Apache

58KB
944 lines

mobc-redis

crates.io

Documentation

Example

use mobc::Pool;
use mobc_redis::redis;
use redis::AsyncCommands;
use mobc_redis::RedisConnectionManager;
use std::time::Instant;

const TEST_KEY: &'static str = "mobc::redis::test";

#[tokio::main]
async fn main() {
    let client = redis::Client::open("redis://127.0.0.1/").unwrap();
    let manager = RedisConnectionManager::new(client);
    let pool = Pool::builder().max_open(20).build(manager);

    let mut conn = pool.get().await.unwrap();
    let _: () = conn.set(TEST_KEY, "hello").await.unwrap();

    const MAX: usize = 5000;

    let now = Instant::now();
    let (tx, mut rx) = tokio::sync::mpsc::channel::<usize>(5000);
    for i in 0..MAX {
        let pool = pool.clone();
        let tx_c = tx.clone();
        tokio::spawn(async move {
            let mut conn = pool.get().await.unwrap();
            let s: String = conn.get(TEST_KEY).await.unwrap();
            assert_eq!(s.as_str(), "hello");
            tx_c.send(i).await.unwrap();
        });
    }
    for _ in 0..MAX {
        rx.recv().await.unwrap();
    }

    println!("cost: {:?}", now.elapsed());
}

Runtimes

You can use either tokio, or async-std as your async runtime.

The default is tokio-comp, but you can use async-std by setting it in the mobc-redis features.

mobc-redis = { version = "0.7", default-features = false, features = ["async-std-comp"] }

Dependencies

~8–20MB
~294K SLoC