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
//! # redis-sentinel-pool
//!
//! 基于 [`redis`] 1.2.1 的 `sentinel` 模块和 [`bb8`] 连接池构建的
//! **Sentinel 感知的异步连接池**。
//!
//! ## 目标
//!
//! * **节点切换对业务透明**:master failover 发生时,业务侧不需要感知,
//!   下一次 [`SentinelPool::get`] 就会拿到指向新 master 的连接。
//! * **快速感知**:可选的后台 watcher 订阅 sentinel 的 `+switch-master` 事件,
//!   收到通知后立即作废全池连接。
//! * **零侵入**:暴露的 `MultiplexedConnection` 与 redis-rs 完全兼容,
//!   所有 [`redis::AsyncCommands`] / `redis::cmd!` 等都可正常使用。
//!
//! ## 快速开始
//!
//! ```no_run
//! use redis::AsyncCommands;
//! use redis_sentinel_pool::{SentinelPool, SentinelPoolConfig};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! 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(32);
//!
//! let pool = SentinelPool::new(cfg).await?;
//!
//! let mut conn = pool.get().await?;
//! let _: () = conn.set("hello", "world").await?;
//! let value: String = conn.get("hello").await?;
//! println!("{value}");
//! # Ok(()) }
//! ```
//!
//! 想要"完全无脑写业务、不操心 failover",用 [`SentinelPool::execute`]:
//!
//! ```no_run
//! use redis::AsyncCommands;
//! use redis_sentinel_pool::{SentinelPool, SentinelPoolConfig};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! # let pool = SentinelPool::new(SentinelPoolConfig::new(vec!["redis://127.0.0.1:26379"], "mymaster")).await?;
//! let result: Option<String> = pool
//!     .execute(|mut conn| async move { conn.get("hello").await })
//!     .await?;
//! # Ok(()) }
//! ```

#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]

mod config;
mod error;
mod manager;
mod pool;
mod watcher;

pub use config::{SentinelPoolConfig, ServerRole};
pub use error::{Result, SentinelPoolError};
pub use manager::{PooledConnection, SentinelConnectionManager};
pub use pool::{ConnectionLease, SentinelPool};

// 重导出常用的 redis 类型,方便调用方少写一行 `use redis::...`。
pub use redis;