#redis-cluster #connection-pool

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

#19 in #redis-cluster

Download history 174/week @ 2024-07-19 144/week @ 2024-07-26 148/week @ 2024-08-02 161/week @ 2024-08-09 242/week @ 2024-08-16 262/week @ 2024-08-23 211/week @ 2024-08-30 305/week @ 2024-09-06 148/week @ 2024-09-13 209/week @ 2024-09-20 257/week @ 2024-09-27 293/week @ 2024-10-04 326/week @ 2024-10-11 345/week @ 2024-10-18 232/week @ 2024-10-25 274/week @ 2024-11-01

1,248 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
~228K SLoC