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    /// Sets the number of times after which the connection will check whether it is active when
36    /// being recycled.
37    ///
38    /// A frequency of 1, means that the connection will check whether it is active every time it
39    /// is recycled.
40    pub recycle_check_frequency: usize,
41}
42
43impl Default for RedisConfigOptions {
44    fn default() -> Self {
45        Self {
46            max_connections: 24,
47            idle_timeout: 60,
48            create_timeout: Some(3),
49            recycle_timeout: Some(2),
50            wait_timeout: None,
51            response_timeout: Some(30),
52            recycle_check_frequency: 100,
53        }
54    }
55}