Skip to content

Commit 6d5e06b

Browse files
committed
Merge remote-tracking branch 'origin/feat/redis'
2 parents 6f614f9 + 837ee58 commit 6d5e06b

File tree

19 files changed

+1088
-6
lines changed

19 files changed

+1088
-6
lines changed

Cargo.lock

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ autoconnect_settings = { path = "./autoconnect/autoconnect-settings" }
103103
autoconnect_web = { path = "./autoconnect/autoconnect-web" }
104104
autoconnect_ws = { path = "./autoconnect/autoconnect-ws" }
105105
autoconnect_ws_clientsm = { path = "./autoconnect/autoconnect-ws/autoconnect-ws-clientsm" }
106-
autopush_common = { path = "./autopush-common", features = ["bigtable"] }
106+
autopush_common = { path = "./autopush-common" }
107107

108108
[profile.release]
109109
debug = 1

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RUST_VER
33
FROM rust:1.83-bookworm AS builder
44
ARG CRATE
5+
ARG BUILD_ARGS
56

67
ADD . /app
78
WORKDIR /app
@@ -16,7 +17,7 @@ RUN \
1617
cargo --version && \
1718
rustc --version && \
1819
mkdir -m 755 bin && \
19-
cargo install --path $CRATE --locked --root /app
20+
cargo install --path $CRATE $BUILD_ARGS --locked --root /app
2021

2122

2223
FROM debian:bookworm-slim

autoconnect/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ docopt = "1.1"
5656
default = ["bigtable"]
5757
bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"]
5858
emulator = ["bigtable"]
59+
redis = ["autopush_common/redis", "autoconnect_settings/redis"]
5960
log_vapid = []

autoconnect/autoconnect-settings/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ autopush_common.workspace = true
2525
# specify the default via the calling crate, in order to simplify default chains.
2626
bigtable = ["autopush_common/bigtable"]
2727
emulator = ["bigtable"]
28+
redis = ["autopush_common/redis"]

autoconnect/autoconnect-settings/src/app_state.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::{sync::Arc, time::Duration};
22

33
#[cfg(feature = "bigtable")]
44
use autopush_common::db::bigtable::BigTableClientImpl;
5+
#[cfg(feature = "redis")]
6+
use autopush_common::db::redis::RedisClientImpl;
57
use cadence::StatsdClient;
68
use config::ConfigError;
79
use fernet::{Fernet, MultiFernet};
@@ -78,6 +80,11 @@ impl AppState {
7880
client.spawn_sweeper(Duration::from_secs(30));
7981
Box::new(client)
8082
}
83+
#[cfg(feature = "redis")]
84+
StorageType::Redis => Box::new(
85+
RedisClientImpl::new(metrics.clone(), &db_settings)
86+
.map_err(|e| ConfigError::Message(e.to_string()))?,
87+
),
8188
_ => panic!(
8289
"Invalid Storage type {:?}. Check {}__DB_DSN.",
8390
storage_type,

autoconnect/autoconnect-settings/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use config::{Config, ConfigError, Environment, File};
1111
use fernet::Fernet;
1212
use lazy_static::lazy_static;
1313
use serde::{Deserialize, Deserializer};
14-
use serde_json::json;
1514

1615
use autopush_common::util::deserialize_u32_to_duration;
1716

@@ -218,6 +217,7 @@ impl Settings {
218217
Ok(())
219218
}
220219

220+
#[cfg(feature = "bigtable")]
221221
pub fn test_settings() -> Self {
222222
let db_dsn = Some("grpc://localhost:8086".to_string());
223223
// BigTable DB_SETTINGS.
@@ -234,6 +234,17 @@ impl Settings {
234234
..Default::default()
235235
}
236236
}
237+
238+
#[cfg(all(feature = "redis", not(feature = "bigtable")))]
239+
pub fn test_settings() -> Self {
240+
let db_dsn = Some("redis://localhost".to_string());
241+
let db_settings = "".to_string();
242+
Self {
243+
db_dsn,
244+
db_settings,
245+
..Default::default()
246+
}
247+
}
237248
}
238249

239250
fn deserialize_f64_to_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>

autoendpoint/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ bigtable = ["autopush_common/bigtable"]
7575
# enable emulator to call locally run data store.
7676
emulator = ["bigtable"]
7777

78+
redis = ["autopush_common/redis"]
79+
7880
# Enable "stub" router for local testing purposes.
7981
# The "stub" will return specified error strings or success
8082
# depending on which `app_id` client is called based on the registration

autoendpoint/src/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use serde_json::json;
1313

1414
#[cfg(feature = "bigtable")]
1515
use autopush_common::db::bigtable::BigTableClientImpl;
16+
#[cfg(feature = "redis")]
17+
use autopush_common::db::redis::RedisClientImpl;
1618
use autopush_common::{
1719
db::{client::DbClient, spawn_pool_periodic_reporter, DbSettings, StorageType},
1820
middleware::sentry::SentryWrapper,
@@ -77,6 +79,8 @@ impl Server {
7779
client.spawn_sweeper(Duration::from_secs(30));
7880
Box::new(client)
7981
}
82+
#[cfg(feature = "redis")]
83+
StorageType::Redis => Box::new(RedisClientImpl::new(metrics.clone(), &db_settings)?),
8084
_ => {
8185
debug!("No idea what {:?} is", &db_settings.dsn);
8286
return Err(ApiErrorKind::General(

autopush-common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ grpcio = { version = "=0.13.0", features = ["openssl"], optional = true }
5959
grpcio-sys = { version = "=0.13.0", optional = true }
6060
protobuf = { version = "=2.28.0", optional = true } # grpcio does not support protobuf 3+
6161
form_urlencoded = { version = "1.2", optional = true }
62+
redis = { version = "0.27.6", features = ["aio", "tokio-comp"]}
6263

6364
[dev-dependencies]
6465
mockito = "0.31"
@@ -80,3 +81,4 @@ bigtable = [
8081
emulator = [
8182
"bigtable",
8283
] # used for testing big table, requires an external bigtable emulator running.
84+
redis = []

0 commit comments

Comments
 (0)