1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! # 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(()) }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
// 重导出常用的 redis 类型,方便调用方少写一行 `use redis::...`。
pub use redis;