pub struct SentinelPoolConfig { /* private fields */ }Expand description
Sentinel 连接池配置。
§示例
use redis_sentinel_pool::SentinelPoolConfig;
let cfg = SentinelPoolConfig::new(
vec![
"redis://127.0.0.1:26379".to_string(),
"redis://127.0.0.1:26380".to_string(),
"redis://127.0.0.1:26381".to_string(),
],
"mymaster",
)
.max_size(32)
.redis_password("secret");Implementations§
Source§impl SentinelPoolConfig
impl SentinelPoolConfig
Sourcepub fn new<I, S>(sentinels: I, service_name: impl Into<String>) -> Self
pub fn new<I, S>(sentinels: I, service_name: impl Into<String>) -> Self
创建一个新的配置。
sentinels—— Sentinel 节点列表,形如redis://host:port。service_name—— Sentinel 中配置的 master 名称,例如mymaster。
Sourcepub fn role(self, role: ServerRole) -> Self
pub fn role(self, role: ServerRole) -> Self
选择拉取的节点角色,默认 ServerRole::Master。
Sourcepub fn connection_timeout(self, timeout: Duration) -> Self
pub fn connection_timeout(self, timeout: Duration) -> Self
借连接的超时时间,默认 5 秒。
Sourcepub fn idle_timeout(self, timeout: Option<Duration>) -> Self
pub fn idle_timeout(self, timeout: Option<Duration>) -> Self
空闲连接最长存活时间,默认 600 秒。
Sourcepub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
pub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
连接最大生命周期,默认 1800 秒。
Sourcepub fn verify_role_on_checkout(self, verify: bool) -> Self
pub fn verify_role_on_checkout(self, verify: bool) -> Self
借连接时是否额外发送 ROLE 校验当前节点仍是 master,默认 true。
关闭后只会执行 PING,可以省一次 RTT,但 failover 检测延迟会变高。
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
execute_with_retry 系列方法的最大重试次数,默认 3。
Sourcepub fn retry_backoff(self, backoff: Duration) -> Self
pub fn retry_backoff(self, backoff: Duration) -> Self
重试之间的退避,每次重试乘以重试次数,默认 100ms(即 100ms、200ms、300ms …)。
Sourcepub fn enable_watcher(self, enable: bool) -> Self
pub fn enable_watcher(self, enable: bool) -> Self
是否启用后台订阅 +switch-master 事件,默认开启。
Sourcepub fn watcher_reconnect_backoff(self, backoff: Duration) -> Self
pub fn watcher_reconnect_backoff(self, backoff: Duration) -> Self
watcher 断开后重连的退避,默认 2 秒。
Sourcepub fn redis_username(self, username: impl Into<String>) -> Self
pub fn redis_username(self, username: impl Into<String>) -> Self
Redis ACL 用户名。
Sourcepub fn redis_password(self, password: impl Into<String>) -> Self
pub fn redis_password(self, password: impl Into<String>) -> Self
Redis 密码。
Sourcepub fn redis_protocol(self, protocol: ProtocolVersion) -> Self
pub fn redis_protocol(self, protocol: ProtocolVersion) -> Self
Redis 协议版本(默认 RESP2)。
Sourcepub fn redis_tls_mode(self, tls_mode: TlsMode) -> Self
pub fn redis_tls_mode(self, tls_mode: TlsMode) -> Self
Redis 节点的 TLS 模式。
Trait Implementations§
Source§impl Clone for SentinelPoolConfig
impl Clone for SentinelPoolConfig
Source§fn clone(&self) -> SentinelPoolConfig
fn clone(&self) -> SentinelPoolConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SentinelPoolConfig
impl RefUnwindSafe for SentinelPoolConfig
impl Send for SentinelPoolConfig
impl Sync for SentinelPoolConfig
impl Unpin for SentinelPoolConfig
impl UnsafeUnpin for SentinelPoolConfig
impl UnwindSafe for SentinelPoolConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more