Skip to main content

SentinelPoolConfig

Struct SentinelPoolConfig 

Source
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

Source

pub fn new<I, S>(sentinels: I, service_name: impl Into<String>) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

创建一个新的配置。

  • sentinels —— Sentinel 节点列表,形如 redis://host:port
  • service_name —— Sentinel 中配置的 master 名称,例如 mymaster
Source

pub fn role(self, role: ServerRole) -> Self

选择拉取的节点角色,默认 ServerRole::Master

Source

pub fn max_size(self, max_size: u32) -> Self

连接池最大连接数,默认 16

Source

pub fn min_idle(self, min_idle: u32) -> Self

最小空闲连接数(提前预热),默认不设置。

Source

pub fn connection_timeout(self, timeout: Duration) -> Self

借连接的超时时间,默认 5 秒。

Source

pub fn idle_timeout(self, timeout: Option<Duration>) -> Self

空闲连接最长存活时间,默认 600 秒。

Source

pub fn max_lifetime(self, lifetime: Option<Duration>) -> Self

连接最大生命周期,默认 1800 秒。

Source

pub fn verify_role_on_checkout(self, verify: bool) -> Self

借连接时是否额外发送 ROLE 校验当前节点仍是 master,默认 true

关闭后只会执行 PING,可以省一次 RTT,但 failover 检测延迟会变高。

Source

pub fn max_retries(self, retries: u32) -> Self

execute_with_retry 系列方法的最大重试次数,默认 3

Source

pub fn retry_backoff(self, backoff: Duration) -> Self

重试之间的退避,每次重试乘以重试次数,默认 100ms(即 100ms、200ms、300ms …)。

Source

pub fn enable_watcher(self, enable: bool) -> Self

是否启用后台订阅 +switch-master 事件,默认开启。

Source

pub fn watcher_reconnect_backoff(self, backoff: Duration) -> Self

watcher 断开后重连的退避,默认 2 秒。

Source

pub fn redis_db(self, db: i64) -> Self

选择 Redis 数据库索引(注意:Sentinel 自身的连接不能使用非 0 库)。

Source

pub fn redis_username(self, username: impl Into<String>) -> Self

Redis ACL 用户名。

Source

pub fn redis_password(self, password: impl Into<String>) -> Self

Redis 密码。

Source

pub fn redis_protocol(self, protocol: ProtocolVersion) -> Self

Redis 协议版本(默认 RESP2)。

Source

pub fn redis_tls_mode(self, tls_mode: TlsMode) -> Self

Redis 节点的 TLS 模式。

Trait Implementations§

Source§

impl Clone for SentinelPoolConfig

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for SentinelPoolConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more