pub struct RedisClusterTemplate { /* private fields */ }Expand description
Redis Cluster template for automatic multi-node cluster setup
Implementations§
Source§impl RedisClusterTemplate
impl RedisClusterTemplate
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new Redis Cluster template with default settings
Sourcepub fn from_env(name: impl Into<String>) -> Self
pub fn from_env(name: impl Into<String>) -> Self
Create a new Redis Cluster template with settings from environment variables.
Falls back to defaults if environment variables are not set.
§Environment Variables
REDIS_CLUSTER_PORT_BASE: Base port for Redis nodes (default: 7000)REDIS_CLUSTER_NUM_MASTERS: Number of master nodes (default: 3)REDIS_CLUSTER_NUM_REPLICAS: Number of replicas per master (default: 0)REDIS_CLUSTER_PASSWORD: Password for cluster authentication (optional)
§Examples
use docker_wrapper::RedisClusterTemplate;
// Uses environment variables if set, otherwise uses defaults
let template = RedisClusterTemplate::from_env("my-cluster");Sourcepub fn get_port_base(&self) -> u16
pub fn get_port_base(&self) -> u16
Get the configured port base
Sourcepub fn get_num_masters(&self) -> usize
pub fn get_num_masters(&self) -> usize
Get the configured number of masters
Sourcepub fn get_num_replicas(&self) -> usize
pub fn get_num_replicas(&self) -> usize
Get the configured number of replicas per master
Sourcepub fn num_masters(self, masters: usize) -> Self
pub fn num_masters(self, masters: usize) -> Self
Set the number of master nodes (minimum 3)
Sourcepub fn num_replicas(self, replicas: usize) -> Self
pub fn num_replicas(self, replicas: usize) -> Self
Set the number of replicas per master
Sourcepub fn cluster_announce_ip(self, ip: impl Into<String>) -> Self
pub fn cluster_announce_ip(self, ip: impl Into<String>) -> Self
Set the IP to announce to other cluster nodes
Sourcepub fn with_persistence(self, volume_prefix: impl Into<String>) -> Self
pub fn with_persistence(self, volume_prefix: impl Into<String>) -> Self
Enable persistence with volume prefix
Sourcepub fn memory_limit(self, limit: impl Into<String>) -> Self
pub fn memory_limit(self, limit: impl Into<String>) -> Self
Set memory limit per node
Sourcepub fn cluster_node_timeout(self, timeout: u32) -> Self
pub fn cluster_node_timeout(self, timeout: u32) -> Self
Set cluster node timeout in milliseconds
Sourcepub fn auto_remove(self) -> Self
pub fn auto_remove(self) -> Self
Enable auto-remove when stopped
Sourcepub fn with_redis_stack(self) -> Self
pub fn with_redis_stack(self) -> Self
Use Redis Stack instead of standard Redis (includes modules like JSON, Search, Graph, TimeSeries, Bloom)
Sourcepub fn with_redis_insight(self) -> Self
pub fn with_redis_insight(self) -> Self
Enable RedisInsight GUI for cluster visualization and management
Sourcepub fn redis_insight_port(self, port: u16) -> Self
pub fn redis_insight_port(self, port: u16) -> Self
Set the port for RedisInsight UI (default: 8001)
Sourcepub fn custom_redis_image(
self,
image: impl Into<String>,
tag: impl Into<String>,
) -> Self
pub fn custom_redis_image( self, image: impl Into<String>, tag: impl Into<String>, ) -> Self
Use a custom Redis image and tag
Sourcepub fn platform(self, platform: impl Into<String>) -> Self
pub fn platform(self, platform: impl Into<String>) -> Self
Set the platform for the containers (e.g., “linux/arm64”, “linux/amd64”)
Sourcepub async fn cluster_info(&self) -> Result<ClusterInfo, TemplateError>
pub async fn cluster_info(&self) -> Result<ClusterInfo, TemplateError>
Check cluster status
Sourcepub async fn is_ready(&self) -> bool
pub async fn is_ready(&self) -> bool
Check if the cluster is ready (all nodes up, slots assigned).
Returns true if the cluster state is “ok”, false otherwise.
§Examples
let template = RedisClusterTemplate::new("my-cluster");
template.start().await?;
if template.is_ready().await {
println!("Cluster is ready!");
}Sourcepub async fn wait_until_ready(
&self,
timeout: Duration,
) -> Result<(), TemplateError>
pub async fn wait_until_ready( &self, timeout: Duration, ) -> Result<(), TemplateError>
Wait for the cluster to become ready, with a timeout.
Polls the cluster state every 500ms until it reports “ok” or the timeout is exceeded.
§Errors
Returns an error if the timeout is exceeded before the cluster becomes ready.
§Examples
let template = RedisClusterTemplate::new("my-cluster");
template.start().await?;
// Wait up to 30 seconds for the cluster to be ready
template.wait_until_ready(Duration::from_secs(30)).await?;
println!("Cluster is ready!");Sourcepub async fn detect_existing(&self) -> Option<RedisClusterConnection>
pub async fn detect_existing(&self) -> Option<RedisClusterConnection>
Check if a Redis cluster is already running at the configured ports.
This is useful in CI environments where an external cluster may be
provided (e.g., via grokzen/redis-cluster Docker image).
Returns connection info if a cluster is detected, None otherwise.
§Examples
let template = RedisClusterTemplate::from_env("my-cluster");
if let Some(conn) = template.detect_existing().await {
println!("Found existing cluster: {}", conn.nodes_string());
} else {
println!("No existing cluster found");
}Sourcepub async fn start_or_detect(
&self,
timeout: Duration,
) -> Result<RedisClusterConnection, TemplateError>
pub async fn start_or_detect( &self, timeout: Duration, ) -> Result<RedisClusterConnection, TemplateError>
Start the cluster, or use an existing one if already running.
This provides a “best of both worlds” approach for hybrid local/CI setups:
- In CI: Uses the externally-provided cluster without starting new containers
- Locally: Starts a new cluster via docker-wrapper
§Examples
// Works in both CI (uses existing) and local (starts new)
let template = RedisClusterTemplate::from_env("test-cluster");
let conn = template.start_or_detect(Duration::from_secs(60)).await?;
println!("Cluster ready at: {}", conn.nodes_string());