Skip to content

Commit

Permalink
redis-db: add settings/config for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
bshifter committed Dec 6, 2024
1 parent ea22e38 commit 35b75a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub async fn db_from_settings(settings: &Settings) -> Result<Db> {
schema::postgres::register_migrations(&mut db);
Ok(Arc::new(db))
}
crate::settings::Database::Redis(redis) => {
let db = RedisDatabase::new(redis.connection_url())
.await
.context("Failed to initialize Redis client")?;
Ok(Arc::new(db))
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions common/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Authentication {
pub enum Database {
SQLite(SQLite),
Postgres(Postgres),
Redis(Redis),
}

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -102,6 +103,18 @@ impl Kerberos {
}
}

#[derive(Debug, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Redis {
connection_url: String,
}

impl Redis {
pub fn connection_url(&self) -> &str {
&self.connection_url
}
}

#[derive(Debug, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct SQLite {
Expand Down

0 comments on commit 35b75a6

Please sign in to comment.