#connection-pool #bb8-connection #tokio

bb8-redis

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

20 releases (breaking)

new 0.18.0 Dec 9, 2024
0.17.0 Sep 13, 2024
0.16.0 Aug 1, 2024
0.15.0 Mar 11, 2024
0.3.0 Mar 18, 2019

#587 in Database interfaces

Download history 22049/week @ 2024-08-24 23403/week @ 2024-08-31 28281/week @ 2024-09-07 34738/week @ 2024-09-14 33410/week @ 2024-09-21 35155/week @ 2024-09-28 34159/week @ 2024-10-05 26334/week @ 2024-10-12 35946/week @ 2024-10-19 39427/week @ 2024-10-26 44231/week @ 2024-11-02 36781/week @ 2024-11-09 48612/week @ 2024-11-16 45657/week @ 2024-11-23 56688/week @ 2024-11-30 74571/week @ 2024-12-07

235,075 downloads per month
Used in 30 crates (25 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

~8–18MB
~226K SLoC