1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::time::Duration;
use crate::resil::{BreakerConfig, BreakerPolicyConfig};
/// Circuit breaker settings for Redis cache commands.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct RedisBreakerConfig {
/// Whether Redis commands and connection acquisition are protected.
pub enabled: bool,
/// Basic breaker thresholds and reset timeout.
pub breaker: BreakerConfig,
/// Rolling-window and adaptive rejection policy.
pub policy: BreakerPolicyConfig,
}
impl RedisBreakerConfig {
/// Creates a production-oriented Redis breaker profile.
pub fn go_zero_defaults() -> Self {
Self {
enabled: true,
breaker: BreakerConfig::default(),
policy: BreakerPolicyConfig::default(),
}
}
/// Creates a Redis breaker profile optimized for fast local tests.
pub fn fast_failure(failure_threshold: u32, reset_timeout: Duration) -> Self {
Self {
enabled: true,
breaker: BreakerConfig {
failure_threshold,
reset_timeout,
},
policy: BreakerPolicyConfig {
min_request_count: u64::MAX,
drop_ratio_percent: 0,
failure_ratio_percent: 100,
force_pass_interval: reset_timeout,
..BreakerPolicyConfig::default()
},
}
}
}