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

bb8-redis-cluster

功能齐全的异步(基于tokio)Redis集群连接池(类似于r2d2)

2个版本

0.1.1 2023年5月8日
0.1.0 2022年10月18日

#2750 in 数据库接口

Download history 145/week @ 2024-03-13 276/week @ 2024-03-20 334/week @ 2024-03-27 239/week @ 2024-04-03 183/week @ 2024-04-10 190/week @ 2024-04-17 172/week @ 2024-04-24 92/week @ 2024-05-01 118/week @ 2024-05-08 192/week @ 2024-05-15 231/week @ 2024-05-22 261/week @ 2024-05-29 170/week @ 2024-06-05 237/week @ 2024-06-12 323/week @ 2024-06-19 254/week @ 2024-06-26

每月 1,032 次下载

BSD-2-Clause

6KB

bb8-redis-cluster

异步Redis集群连接池(bb8)。

示例

#[tokio::main]
async fn main() {
    let manager = RedisConnectionManager::new(vec!["redis://127.0.0.1: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:

为bb8连接池提供Redis集群支持。

示例

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://127.0.0.1"]).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;
}

依赖项

~7–19MB
~243K SLoC