redis-sentinel-pool 0.1.0

An async Redis Sentinel-aware connection pool built on top of redis-rs and bb8, with transparent master failover.
Documentation
//! 最基础的使用示例:拿一条连接、SET 一个 key、GET 回来。
//!
//! 运行前先准备好 Sentinel 集群(端口按需修改),然后:
//!
//! ```text
//! RUST_LOG=info cargo run --example basic
//! ```

use anyhow::Result;
use redis::AsyncCommands;
use redis_sentinel_pool::{SentinelPool, SentinelPoolConfig};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
        .init();

    let cfg = SentinelPoolConfig::new(
        vec![
            "redis://127.0.0.1:26379",
            "redis://127.0.0.1:26380",
            "redis://127.0.0.1:26381",
        ],
        "mymaster",
    )
    .max_size(16);

    let pool = SentinelPool::new(cfg).await?;

    {
        let mut conn = pool.get().await?;
        let _: () = conn.set("hello", "world").await?;
        let val: String = conn.get("hello").await?;
        println!("hello = {val}");
    }

    pool.shutdown().await;
    Ok(())
}