#[cfg(feature = "template-redis")]
use docker_wrapper::RedisSentinelTemplate;
#[cfg(feature = "template-redis")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Setting up Redis Sentinel cluster...");
let sentinel = RedisSentinelTemplate::new("test-sentinel")
.master_name("mymaster")
.num_replicas(2)
.num_sentinels(3)
.quorum(2)
.password("sentinel-password")
.with_persistence();
let connection_info = sentinel.start().await?;
println!("\nโ
Redis Sentinel cluster started successfully!");
println!("\n๐ Cluster Information:");
println!(
" Master: {}:{}",
connection_info.master_host, connection_info.master_port
);
println!(" Replicas: {:?}", connection_info.replica_ports);
println!(" Sentinels:");
for sentinel in &connection_info.sentinels {
println!(" - {}:{}", sentinel.host, sentinel.port);
}
println!("\n๐ Connection URLs:");
println!(" Master URL: {}", connection_info.master_url());
println!(" Sentinel URLs: {:?}", connection_info.sentinel_urls());
println!("\n๐ฆ Containers:");
for container in &connection_info.containers {
println!(" - {}", container);
}
println!("\nโณ Cluster will run for 5 seconds for testing...");
println!("You can test failover by stopping the master container:");
println!(" docker stop {}-master", connection_info.name);
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
println!("\n๐งน Cleaning up...");
connection_info.stop().await?;
println!("โ
Cleanup complete!");
Ok(())
}
#[cfg(not(feature = "template-redis"))]
fn main() {
eprintln!("This example requires the 'template-redis' feature to be enabled.");
eprintln!("Run with: cargo run --example test_sentinel --features template-redis");
}