aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-04-06 18:00:34 +0200
committerrtkay123 <dev@kanjala.com>2026-04-06 18:00:34 +0200
commitd575e966a422ea87508ef5370b2904f4818c6773 (patch)
tree171834a526674de5647631fbcb0aff1e0e7bdf9c
parent3f708c5fffed105b27965f8e844a26de6bdf9662 (diff)
downloadsellershut-d575e966a422ea87508ef5370b2904f4818c6773.tar.bz2
sellershut-d575e966a422ea87508ef5370b2904f4818c6773.zip
feat(cache): connect
-rw-r--r--Cargo.lock14
-rw-r--r--compose.yaml14
-rw-r--r--crates/sellershut/Cargo.toml2
-rw-r--r--crates/sellershut/src/config/cache/mod.rs39
4 files changed, 42 insertions, 27 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0e5cb2c..00ea4f2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2365,6 +2365,8 @@ dependencies = [
"sha2 0.10.9",
"smallvec",
"thiserror 2.0.18",
+ "tokio",
+ "tokio-stream",
"tracing",
"url",
]
@@ -2401,6 +2403,7 @@ dependencies = [
"sqlx-core",
"sqlx-postgres",
"syn",
+ "tokio",
"url",
]
@@ -2708,6 +2711,17 @@ dependencies = [
]
[[package]]
+name = "tokio-stream"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70"
+dependencies = [
+ "futures-core",
+ "pin-project-lite",
+ "tokio",
+]
+
+[[package]]
name = "tokio-util"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/compose.yaml b/compose.yaml
index ceaa5fc..59b4021 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -21,6 +21,20 @@ services:
timeout: 5s
retries: 3
+ cache:
+ image: docker.io/valkey/valkey:9.0.3-alpine3.23
+ restart: always
+ ports:
+ - 6379:6379
+ networks:
+ - sellershut
+ healthcheck:
+ test: ["CMD", "valkey-cli", "ping"]
+ interval: 10s
+ timeout: 5s
+ retries: 5
+ start_period: 5s
+
volumes:
db:
driver: local
diff --git a/crates/sellershut/Cargo.toml b/crates/sellershut/Cargo.toml
index caf6fd0..df619f8 100644
--- a/crates/sellershut/Cargo.toml
+++ b/crates/sellershut/Cargo.toml
@@ -19,7 +19,7 @@ secrecy = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sh-util = { workspace = true, features = ["cache"] }
-sqlx = { workspace = true, features = ["migrate"] }
+sqlx = { workspace = true, features = ["migrate", "runtime-tokio"] }
tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread"] }
toml = "1.1.2"
tracing.workspace = true
diff --git a/crates/sellershut/src/config/cache/mod.rs b/crates/sellershut/src/config/cache/mod.rs
index 136c3a4..525b3aa 100644
--- a/crates/sellershut/src/config/cache/mod.rs
+++ b/crates/sellershut/src/config/cache/mod.rs
@@ -86,12 +86,8 @@ impl CacheConfig {
cache_password: higher.cache_password.or(self.cache_password),
cache_database: higher.cache_database.or(self.cache_database),
cache_service_name: higher.cache_service_name.or(self.cache_service_name),
- cache_tls_mode_secure: higher
- .cache_tls_mode_secure
- .or(self.cache_tls_mode_secure),
- cache_use_resp3: higher
- .cache_use_resp3
- .or(self.cache_use_resp3),
+ cache_tls_mode_secure: higher.cache_tls_mode_secure.or(self.cache_tls_mode_secure),
+ cache_use_resp3: higher.cache_use_resp3.or(self.cache_use_resp3),
}
}
@@ -119,20 +115,15 @@ impl CacheConfig {
self.cache_mode.unwrap_or(CacheMode::Standalone)
}
- pub fn url(&self) -> anyhow::Result<String> {
+ pub fn url(&self) -> anyhow::Result<String> {
if let Some(url) = &self.cache_url {
return Ok(url.clone());
}
match self.mode() {
CacheMode::Standalone => {
- let host = self
- .cache_host
- .as_deref()
- .context("cache.host")?;
- let port = self
- .cache_port
- .context("cache.port")?;
+ let host = self.cache_host.as_deref().context("cache.host")?;
+ let port = self.cache_port.context("cache.port")?;
let db = self.cache_database.unwrap_or(0);
let auth = match (&self.cache_username, &self.cache_password) {
@@ -145,10 +136,7 @@ impl CacheConfig {
Ok(format!("redis://{}{}:{}/{}", auth, host, port, db))
}
CacheMode::Clustered | CacheMode::Sentinel => {
- self.cache_nodes
- .first()
- .cloned()
- .context("cache.nodes[0]")
+ self.cache_nodes.first().cloned().context("cache.nodes[0]")
}
}
}
@@ -180,10 +168,9 @@ impl TryFrom<&CacheConfig> for SentinelConfig {
}
Ok(SentinelConfig {
- service_name: value
- .cache_service_name
- .clone()
- .ok_or(CacheConfigConversionError::MissingField("cache.service_name"))?,
+ service_name: value.cache_service_name.clone().ok_or(
+ CacheConfigConversionError::MissingField("cache.service_name"),
+ )?,
redis_tls_mode_secure: value.cache_tls_mode_secure.unwrap_or(false),
redis_db: value.cache_database.map(i64::from),
redis_username: value
@@ -211,15 +198,15 @@ impl TryFrom<&CacheConfig> for RedisVariant {
type Error = anyhow::Error;
fn try_from(value: &CacheConfig) -> Result<Self, Self::Error> {
- let s = SentinelConfig::try_from(value)?;
-
match value.mode() {
CacheMode::Standalone => Ok(RedisVariant::NonClustered),
CacheMode::Clustered => Ok(RedisVariant::Clustered),
- CacheMode::Sentinel => Ok(RedisVariant::Sentinel(s)),
+ CacheMode::Sentinel => {
+ let s = SentinelConfig::try_from(value)?;
+ Ok(RedisVariant::Sentinel(s))
+ }
}
}
-
}
impl TryFrom<CacheConfig> for sh_util::cache::RedisVariant {