external_stores/
external_stores.rs1use rust_zero_core::{
2 MongoStore, MongoStoreConfig, RedisStore, RedisStoreConfig, SqlStoreConfig, SqliteStore,
3};
4use std::env;
5
6#[tokio::main(flavor = "current_thread")]
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1/".to_owned());
9 let mongo_url =
10 env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://127.0.0.1:27017".to_owned());
11 let sqlite_url = env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_owned());
12
13 let redis = RedisStore::new(RedisStoreConfig::new(redis_url))?;
14 let sql = SqliteStore::connect_sqlite(SqlStoreConfig::new(sqlite_url)).await?;
15 let mongo = MongoStore::connect(MongoStoreConfig::new(mongo_url, "rust_zero_example")).await?;
16
17 redis.ping().await?;
18 sql.health_check().await?;
19 mongo.health_check().await?;
20 println!("Redis, SQLite, and MongoDB are ready");
21 Ok(())
22}