relay_redis/
config.rs

1use serde::{Deserialize, Serialize};
2
3/// Additional configuration options for a redis client.
4#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
5pub struct RedisConfigOptions {
6    /// Maximum number of connections managed by the pool.
7    pub max_connections: u32,
8    /// Sets the idle timeout used by the pool, in seconds.
9    ///
10    /// The idle timeout defines the maximum time a connection will be kept in the pool if unused.
11    pub idle_timeout: u64,
12    /// Sets the maximum time in seconds to wait when establishing a new Redis connection.
13    ///
14    /// If a connection cannot be established within this duration, it is considered a failure.
15    /// Applies when the pool needs to grow or create fresh connections.
16    pub create_timeout: Option<u64>,
17    /// Sets the maximum time in seconds to validate an existing connection when it is recycled.
18    ///
19    /// Recycling involves checking whether an idle connection is still alive before reuse.
20    /// If validation exceeds this timeout, the connection is discarded and a new fetch from the pool
21    /// is attempted.
22    pub recycle_timeout: Option<u64>,
23    /// Sets the maximum time, in seconds, that a caller is allowed to wait
24    /// when requesting a connection from the pool.
25    ///
26    /// If a connection does not become available within this period, the attempt
27    /// will fail with a timeout error. This setting helps prevent indefinite
28    /// blocking when the pool is exhausted.
29    pub wait_timeout: Option<u64>,
30    /// Sets the maximum time in seconds to wait for a result when sending a Redis command.
31    ///
32    /// If a command exceeds this timeout, the connection will be recycled.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub response_timeout: Option<u64>,
35}
36
37impl Default for RedisConfigOptions {
38    fn default() -> Self {
39        Self {
40            max_connections: 24,
41            idle_timeout: 60,
42            create_timeout: Some(3),
43            recycle_timeout: Some(2),
44            wait_timeout: None,
45            response_timeout: Some(30),
46        }
47    }
48}