Skip to main content

PoolConfig

Struct PoolConfig 

Source
pub struct PoolConfig {
    pub name: String,
    pub size: usize,
    pub min_size: Option<usize>,
    pub max_size: Option<usize>,
    pub idle_timeout: Option<Duration>,
    pub dispatch: DispatchStrategy,
    pub health_check_interval: Option<Duration>,
    pub acquisition_timeout: Option<Duration>,
    pub metrics_recorder: Option<Arc<dyn MetricsRecorder>>,
}
Expand description

Configuration for a connection pool.

Fields§

§name: String

Stable name used to identify this pool in metrics.

Applications with multiple pools should give each one a distinct name so their utilization and acquisition metrics remain distinguishable. Defaults to "redis-tower".

§size: usize

Legacy fixed size and fallback for omitted dynamic bounds.

With neither min_size nor max_size, the pool remains fixed at this size. Prefer Self::bounds when opting into dynamic sizing.

§min_size: Option<usize>

Optional minimum number of live connections.

When omitted, Self::size is used. Idle reaping never shrinks below this value. Set this below max_size to opt into dynamic sizing.

§max_size: Option<usize>

Optional maximum number of live connections.

When omitted, Self::size is used. A factory-backed pool creates new connections up to this bound when every live slot is contended.

§idle_timeout: Option<Duration>

How long a completely idle connection may remain before an explicitly spawned idle reaper removes it.

Setting this value does not spawn a task. Call ConnectionPool::spawn_idle_reaper and retain its owned handle.

§dispatch: DispatchStrategy

How to select which connection handles each command.

§health_check_interval: Option<Duration>

If set, connections idle longer than this duration are PINGed before use.

This provides lazy health checking: when a connection has been idle beyond this interval, a PING is sent before dispatching the actual command. If the PING fails and the pool has a factory, the dead slot is replaced before the command is retried. If no factory is present, the error is returned to the caller.

§acquisition_timeout: Option<Duration>

Maximum time to wait for a connection slot to become available.

When all connections in the pool are busy, new callers block waiting for a slot to free up. If the wait exceeds this duration, RedisError::PoolAcquisitionTimeout is returned, so pool exhaustion fails fast as a timeout instead of stalling the caller indefinitely.

Defaults to PoolConfig::DEFAULT_ACQUISITION_TIMEOUT (5 seconds). Set it to None – via PoolConfig::disable_acquisition_timeout – to wait forever, restoring the previous unbounded behavior. Duration::ZERO is distinct from None: it permits an immediately available slot but never waits for a busy one. A command wrapped in redis_tower_core::WithDeadline can impose an earlier limit; the earliest deadline wins.

§metrics_recorder: Option<Arc<dyn MetricsRecorder>>

Optional recorder for pool lifecycle metrics.

When set, the pool reports connection acquisition latency and timeouts, lazy health-check failures, and successful connection replacements.

Implementations§

Source§

impl PoolConfig

Source

pub const DEFAULT_ACQUISITION_TIMEOUT: Duration

Default upper bound on how long a caller waits for a connection slot.

Used by PoolConfig::default. Five seconds is long enough to ride out brief contention but short enough that genuine pool exhaustion surfaces as a RedisError::PoolAcquisitionTimeout rather than an unbounded stall that masquerades as a hang.

Source

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

Set the stable name used to identify this pool in metrics.

Source

pub fn size(self, size: usize) -> Self

Set the pool size.

Source

pub fn min_size(self, min_size: usize) -> Self

Set the minimum number of live connections maintained by the pool.

Source

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

Set the maximum number of live connections permitted in the pool.

Source

pub fn bounds(self, min_size: usize, max_size: usize) -> Self

Set both dynamic sizing bounds.

Source

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

Set the idle duration after which a reaper may remove a connection.

This only configures policy. No background task exists until ConnectionPool::spawn_idle_reaper is called.

Source

pub fn dispatch(self, strategy: DispatchStrategy) -> Self

Set the dispatch strategy.

Source

pub fn health_check_interval(self, interval: Duration) -> Self

Set the health check interval.

If set, connections idle longer than this are PINGed before use to verify they are still alive.

Source

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

Set the maximum time to wait for a connection slot.

If all connections are busy when a command is submitted and a slot does not free up within timeout, the call returns RedisError::PoolAcquisitionTimeout. Overrides the bounded PoolConfig::DEFAULT_ACQUISITION_TIMEOUT. Pass Duration::ZERO for fail-fast acquisition that never waits; use Self::disable_acquisition_timeout to wait without a bound.

Source

pub fn disable_acquisition_timeout(self) -> Self

Wait forever for a connection slot, disabling the acquisition timeout.

This restores the previous behavior where a saturated pool blocks the caller indefinitely. Prefer the bounded default unless an unbounded wait is genuinely what you want – an unbounded wait turns pool exhaustion into a silent hang rather than a surfaced RedisError::PoolAcquisitionTimeout.

Source

pub fn metrics_recorder(self, recorder: Arc<dyn MetricsRecorder>) -> Self

Set the recorder that receives pool lifecycle metric events.

Trait Implementations§

Source§

impl Clone for PoolConfig

Source§

fn clone(&self) -> Self

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 PoolConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PoolConfig

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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