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

bb8-redis-cluster

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

2 releases

0.1.1 May 8, 2023
0.1.0 Oct 18, 2022

#2904 in Database interfaces

Download history 213/week @ 2024-11-15 85/week @ 2024-11-22 233/week @ 2024-11-29 287/week @ 2024-12-06 248/week @ 2024-12-13 193/week @ 2024-12-20 88/week @ 2024-12-27 139/week @ 2025-01-03 308/week @ 2025-01-10 181/week @ 2025-01-17 306/week @ 2025-01-24 342/week @ 2025-01-31 343/week @ 2025-02-07 153/week @ 2025-02-14 102/week @ 2025-02-21 149/week @ 2025-02-28

782 downloads per month

BSD-2-Clause

6KB

bb8-redis-cluster

A Async redis cluster connection pool (bb8).

Example

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

    for _ in 0..20 {
        let pool = pool.clone();
        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);
        });
    }
}

lib.rs:

Redis Cluster support for the bb8 connection pool.

Example

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

#[tokio::main]
async fn main() {
    let manager = RedisConnectionManager::new(vec!["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
~233K SLoC