#connection-pool #bb8-connection #tokio

bb8-redis

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

22 releases (breaking)

new 0.21.0 Feb 17, 2025
0.18.0 Dec 9, 2024
0.17.0 Sep 13, 2024
0.15.0 Mar 11, 2024
0.3.0 Mar 18, 2019

#497 in Database interfaces

Download history 41573/week @ 2024-10-30 37513/week @ 2024-11-06 42867/week @ 2024-11-13 56653/week @ 2024-11-20 42070/week @ 2024-11-27 64993/week @ 2024-12-04 85548/week @ 2024-12-11 63384/week @ 2024-12-18 23554/week @ 2024-12-25 58344/week @ 2025-01-01 125013/week @ 2025-01-08 119000/week @ 2025-01-15 154051/week @ 2025-01-22 185515/week @ 2025-01-29 179848/week @ 2025-02-05 148568/week @ 2025-02-12

689,844 downloads per month
Used in 35 crates (30 directly)

MIT license

55KB
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

~8–17MB
~223K SLoC