#connection-pool #redis #bb8-connection #tokio #r2d2

bb8-redis

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

17 releases (breaking)

0.15.0 Mar 11, 2024
0.14.0 Dec 6, 2023
0.13.1 May 31, 2023
0.12.0 Oct 17, 2022
0.3.0 Mar 18, 2019

#586 in Database interfaces

Download history 9374/week @ 2024-01-24 10310/week @ 2024-01-31 9386/week @ 2024-02-07 11072/week @ 2024-02-14 10560/week @ 2024-02-21 10330/week @ 2024-02-28 11097/week @ 2024-03-06 11766/week @ 2024-03-13 10641/week @ 2024-03-20 7413/week @ 2024-03-27 8066/week @ 2024-04-03 9063/week @ 2024-04-10 10626/week @ 2024-04-17 8736/week @ 2024-04-24 8624/week @ 2024-05-01 7664/week @ 2024-05-08

37,317 downloads per month
Used in 18 crates (17 directly)

MIT license

42KB
827 lines

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

~6–19MB
~244K SLoC