Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis database backend #206

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
redis:
image: redis
ports:
- 6379:6379

steps:
- uses: actions/checkout@v4
Expand All @@ -57,4 +61,5 @@ jobs:
export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="postgres"
export POSTGRES_DBNAME="test"
export REDIS_URL="redis://redis:6379"
cargo test --verbose
34 changes: 33 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ chrono = { version = "0.4.26", default-features = false, features = ["clock"] }
encoding_rs = "0.8.32"
deadpool-postgres = "0.14.0"
deadpool-sqlite = "0.5.0"
deadpool-redis = "0.18.0"
openssl = "0.10.66"
postgres-openssl = "0.5.0"
strum = { version = "0.26.1", features = ["derive"] }
Expand Down
9 changes: 9 additions & 0 deletions common/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
bookmark::BookmarkData,
database::postgres::PostgresDatabase,
database::sqlite::SQLiteDatabase,
database::redis::RedisDatabase,
heartbeat::{HeartbeatData, HeartbeatsCache},
settings::Settings,
subscription::{
Expand All @@ -21,6 +22,8 @@ use self::schema::{Migration, Version};
pub mod postgres;
pub mod schema;
pub mod sqlite;
pub mod redis;
pub mod redisdomain;

pub type Db = Arc<dyn Database + Send + Sync>;

Expand All @@ -40,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
Loading
Loading