#redis-cluster #connection-pool #bb8-connection #tokio #connection-manager #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

#2668 in Database interfaces

Download history 10/week @ 2024-01-02 3/week @ 2024-01-30 32/week @ 2024-02-06 238/week @ 2024-02-13 234/week @ 2024-02-20 240/week @ 2024-02-27 173/week @ 2024-03-05 148/week @ 2024-03-12 191/week @ 2024-03-19 376/week @ 2024-03-26 271/week @ 2024-04-02 180/week @ 2024-04-09 167/week @ 2024-04-16

1,055 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

~7–19MB
~254K SLoC