mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 09:04:55 +00:00
fix: make Redis key TTL variable (#6821)
This commit is contained in:
@@ -26,11 +26,6 @@ use util::{cmd, redis_pipe};
|
|||||||
|
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
const DEFAULT_EXPIRY: i64 = 60 * 60 * 12; // 12 hours
|
|
||||||
const ACTUAL_EXPIRY: i64 = 60 * 30; // 30 minutes
|
|
||||||
const VERSION_DEFAULT_EXPIRY: i64 = 60 * 60 * 48; // 48 hours
|
|
||||||
const VERSION_ACTUAL_EXPIRY: i64 = 60 * 60 * 24; // 24 hours
|
|
||||||
|
|
||||||
// Bound how many commands we send in a single Redis pipeline. The multiplexed
|
// Bound how many commands we send in a single Redis pipeline. The multiplexed
|
||||||
// connection's BytesMut write buffer keeps its peak capacity for the life of
|
// connection's BytesMut write buffer keeps its peak capacity for the life of
|
||||||
// the connection, so larger pipelines cause higher steady-state RSS.
|
// the connection, so larger pipelines cause higher steady-state RSS.
|
||||||
@@ -150,10 +145,11 @@ where
|
|||||||
fn cache_expiries(namespace: &str) -> (i64, i64) {
|
fn cache_expiries(namespace: &str) -> (i64, i64) {
|
||||||
// Namespaces may embed a version suffix like `:v1`, so split it out.
|
// Namespaces may embed a version suffix like `:v1`, so split it out.
|
||||||
match namespace.split_once(':').map(|t| t.0).unwrap_or(namespace) {
|
match namespace.split_once(':').map(|t| t.0).unwrap_or(namespace) {
|
||||||
"versions" | "versions_files" => {
|
"versions" | "versions_files" => (
|
||||||
(VERSION_DEFAULT_EXPIRY, VERSION_ACTUAL_EXPIRY)
|
ENV.REDIS_VERSION_DEFAULT_EXPIRY,
|
||||||
}
|
ENV.REDIS_VERSION_ACTUAL_EXPIRY,
|
||||||
_ => (DEFAULT_EXPIRY, ACTUAL_EXPIRY),
|
),
|
||||||
|
_ => (ENV.REDIS_DEFAULT_EXPIRY, ENV.REDIS_ACTUAL_EXPIRY),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,7 +740,7 @@ impl RedisConnection {
|
|||||||
cmd.arg(format!("{}_{}:{}", self.meta_namespace, namespace, id))
|
cmd.arg(format!("{}_{}:{}", self.meta_namespace, namespace, id))
|
||||||
.arg(data)
|
.arg(data)
|
||||||
.arg("EX")
|
.arg("EX")
|
||||||
.arg(expiry.unwrap_or(DEFAULT_EXPIRY));
|
.arg(expiry.unwrap_or(ENV.REDIS_DEFAULT_EXPIRY));
|
||||||
redis_execute::<()>(&mut cmd, &mut self.connection).await?;
|
redis_execute::<()>(&mut cmd, &mut self.connection).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,6 +294,10 @@ vars! {
|
|||||||
REDIS_WAIT_TIMEOUT_MS: u64 = 15000u64;
|
REDIS_WAIT_TIMEOUT_MS: u64 = 15000u64;
|
||||||
REDIS_MAX_CONNECTIONS: u32 = 10000u32;
|
REDIS_MAX_CONNECTIONS: u32 = 10000u32;
|
||||||
REDIS_MIN_CONNECTIONS: usize = 0usize;
|
REDIS_MIN_CONNECTIONS: usize = 0usize;
|
||||||
|
REDIS_DEFAULT_EXPIRY: i64 = 60 * 60 * 12;
|
||||||
|
REDIS_ACTUAL_EXPIRY: i64 = 60 * 30;
|
||||||
|
REDIS_VERSION_DEFAULT_EXPIRY: i64 = 60 * 60 * 12;
|
||||||
|
REDIS_VERSION_ACTUAL_EXPIRY: i64 = 60 * 30;
|
||||||
REDIS_ENCODING_FORMAT: crate::database::redis::EncodingFormat = crate::database::redis::EncodingFormat::Json;
|
REDIS_ENCODING_FORMAT: crate::database::redis::EncodingFormat = crate::database::redis::EncodingFormat::Json;
|
||||||
REDIS_COMPRESSION_LEVEL: i32 = 0i32;
|
REDIS_COMPRESSION_LEVEL: i32 = 0i32;
|
||||||
REDIS_COMPRESSION_ALGORITHM: crate::database::redis::Codec = crate::database::redis::Codec::Lz4;
|
REDIS_COMPRESSION_ALGORITHM: crate::database::redis::Codec = crate::database::redis::Codec::Lz4;
|
||||||
|
|||||||
Reference in New Issue
Block a user