#connection-pool #bb8-connection #tokio

bb8-redis

Full-featured async (tokio-based) redis connection pool (like r2d2)

19 releases (breaking)

0.17.0 Sep 13, 2024
0.15.0 Mar 11, 2024
0.14.0 Dec 6, 2023
0.13.1 May 31, 2023
0.3.0 Mar 18, 2019

#731 in Database interfaces

Download history 49763/week @ 2024-07-18 28847/week @ 2024-07-25 46750/week @ 2024-08-01 51101/week @ 2024-08-08 35762/week @ 2024-08-15 42276/week @ 2024-08-22 18662/week @ 2024-08-29 27824/week @ 2024-09-05 34547/week @ 2024-09-12 32846/week @ 2024-09-19 36769/week @ 2024-09-26 33860/week @ 2024-10-03 25424/week @ 2024-10-10 35715/week @ 2024-10-17 36832/week @ 2024-10-24 41888/week @ 2024-10-31

148,500 downloads per month
Used in 27 crates (24 directly)

MIT license

52KB
1K SLoC

Redis support for the bb8 connection pool.

Example

use futures_util::future::join_all;
use bb8_redis::{
    bb8,
    redis::{cmd, AsyncCommands},
    RedisConnectionManager
};

#[tokio::main]
async fn main() {
    let manager = RedisConnectionManager::new("redis://localhost").unwrap();
    let pool = bb8::Pool::builder().build(manager).await.unwrap();

    let mut handles = vec![];

    for _i in 0..10 {
        let pool = pool.clone();

        handles.push(tokio::spawn(async move {
            let mut conn = pool.get().await.unwrap();

            let reply: String = cmd("PING").query_async(&mut *conn).await.unwrap();

            assert_eq!("PONG", reply);
        }));
    }

    join_all(handles).await;
}

Dependencies

~7–16MB
~213K SLoC