-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_sentinel.rs
More file actions
63 lines (52 loc) · 2.06 KB
/
test_sentinel.rs
File metadata and controls
63 lines (52 loc) · 2.06 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Test the Redis Sentinel template
//!
//! Run with: cargo run --example test_sentinel --all-features
#[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...");
// Create a 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();
// Start the cluster
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);
// Keep running for testing
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");
}