#connection-pool #bb8-connection #tokio

bb8-redis

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

21 releases (breaking)

new 0.20.0 Jan 8, 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

#580 in Database interfaces

Download history 33390/week @ 2024-09-24 35583/week @ 2024-10-01 29154/week @ 2024-10-08 33728/week @ 2024-10-15 34412/week @ 2024-10-22 41353/week @ 2024-10-29 40618/week @ 2024-11-05 40116/week @ 2024-11-12 52066/week @ 2024-11-19 44273/week @ 2024-11-26 61188/week @ 2024-12-03 82342/week @ 2024-12-10 78107/week @ 2024-12-17 24398/week @ 2024-12-24 41903/week @ 2024-12-31 98004/week @ 2025-01-07

256,750 downloads per month
Used in 34 crates (29 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–18MB
~216K SLoC