use crate::template::{HealthCheck, VolumeMount};
#[allow(dead_code)]
pub const DEFAULT_REDIS_PORT: u16 = 6379;
pub const DEFAULT_REDIS_IMAGE: &str = "redis";
pub const DEFAULT_REDIS_TAG: &str = "7-alpine";
pub const REDIS_STACK_IMAGE: &str = "redis/redis-stack";
pub const REDIS_STACK_SERVER_IMAGE: &str = "redis/redis-stack-server";
pub const REDIS_STACK_TAG: &str = "7.4.0-v3";
pub const REDIS_INSIGHT_IMAGE: &str = "redis/redisinsight";
pub const REDIS_INSIGHT_CLUSTER_IMAGE: &str = "redislabs/redisinsight";
pub const REDIS_INSIGHT_TAG: &str = "2.60";
pub const DEFAULT_REDIS_INSIGHT_PORT: u16 = 5540;
pub const REDIS_TLS_DIR: &str = "/tls";
pub const REDIS_TLS_CERT_FILE: &str = "redis.crt";
pub const REDIS_TLS_KEY_FILE: &str = "redis.key";
pub const REDIS_TLS_CA_FILE: &str = "ca.crt";
pub const DEFAULT_REDIS_TLS_PORT: u16 = 6380;
pub fn default_redis_health_check() -> HealthCheck {
HealthCheck {
test: vec!["redis-cli".to_string(), "ping".to_string()],
interval: "10s".to_string(),
timeout: "5s".to_string(),
retries: 3,
start_period: "10s".to_string(),
}
}
#[allow(dead_code)]
#[allow(clippy::uninlined_format_args)]
pub fn redis_connection_string(host: &str, port: u16, password: Option<&str>) -> String {
match password {
Some(pass) => format!("redis://:{}@{}:{}", pass, host, port),
None => format!("redis://{}:{}", host, port),
}
}
#[allow(dead_code)]
pub fn redis_tls_connection_string(host: &str, port: u16, password: Option<&str>) -> String {
match password {
Some(pass) => format!("rediss://:{pass}@{host}:{port}"),
None => format!("rediss://{host}:{port}"),
}
}
pub fn redis_tls_server_args(tls_container_port: u16) -> Vec<String> {
vec![
"--tls-port".to_string(),
tls_container_port.to_string(),
"--tls-cert-file".to_string(),
format!("{REDIS_TLS_DIR}/{REDIS_TLS_CERT_FILE}"),
"--tls-key-file".to_string(),
format!("{REDIS_TLS_DIR}/{REDIS_TLS_KEY_FILE}"),
"--tls-ca-cert-file".to_string(),
format!("{REDIS_TLS_DIR}/{REDIS_TLS_CA_FILE}"),
]
}
pub fn redis_tls_volume(certs_dir: impl Into<String>) -> VolumeMount {
VolumeMount {
source: certs_dir.into(),
target: REDIS_TLS_DIR.to_string(),
read_only: true,
}
}
pub fn redis_data_volume(volume_name: impl Into<String>) -> VolumeMount {
VolumeMount {
source: volume_name.into(),
target: "/data".to_string(),
read_only: false,
}
}
pub fn redis_config_volume(config_path: impl Into<String>) -> VolumeMount {
VolumeMount {
source: config_path.into(),
target: "/usr/local/etc/redis/redis.conf".to_string(),
read_only: true,
}
}