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