use std::time::Duration;
use redis::{Client, Commands};
use tracing::{info, Level};
use rustainers::images::Redis;
use rustainers::runner::{RunOption, Runner};
use rustainers::Container;
mod common;
pub use self::common::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
init_tracing(Level::INFO);
let runner = Runner::auto()?;
let image = Redis::default();
let options = RunOption::builder()
.with_remove(true)
.with_wait_interval(Duration::from_millis(96))
.build();
let container = runner.start_with_options(image, options).await?;
info!("Now I can use {container}");
do_something_in_redis(&container).await?;
Ok(())
}
async fn do_something_in_redis(redis: &Container<Redis>) -> anyhow::Result<()> {
let endpoint = redis.endpoint().await?;
info!("Using Redis at {endpoint}");
let client = Client::open(endpoint)?;
let mut con = client.get_connection()?;
let key = "plop";
let _: () = con.set(key, "plop-123")?;
let result = con.get::<_, String>(&key)?;
info!("Result: {result}");
Ok(())
}