feat(labrinth): Redis Cluster (#6771)

* chore(labrinth): bump to redis 1.4.1

* feat(labrinth): redis cluster

* chore: cleanup

* feat(labrinth): cache locking

* fix(labrinth): clippy

* chore(labrinth): cleanup env, remove postcard support

* chore(ci): fix test env for labrinth

* chore(labrinth): bump all key versions

* chore(labrinth): improve redis key identities handling

* chore(labrinth): simplify deadline handling

* chore(labrinth): remove unused lease tracking

* chore(labrinth): remove distributed cache locking for now

* chore(labrinth): improve redis backend init error

* feat(labrinth): expose redis read replica strategy

* chore(ci): remove other connection mode tests

* chore: split xredis crate

* feat(xredis): primaries routing

* chore: tombi fmt

* chore: clippy

* chore: update query cache
This commit is contained in:
François-Xavier Talbot
2026-07-23 11:35:02 +02:00
committed by GitHub
parent 11af2651ef
commit b4d681e713
146 changed files with 4741 additions and 2000 deletions
+47 -13
View File
@@ -5,6 +5,11 @@ use eyre::{Context, eyre};
use rust_decimal::Decimal;
use serde::de::DeserializeOwned;
use xredis::{
CacheLockingStrategy, ReadReplicaStrategy, RedisConnectionType,
RedisTopology,
};
macro_rules! vars {
(
$(
@@ -130,7 +135,49 @@ vars! {
LABRINTH_SUBSCRIPTIONS_KEY: String = "";
RATE_LIMIT_IGNORE_KEY: String = "";
DATABASE_URL: String = "postgresql://labrinth:labrinth@localhost/labrinth";
// Redis
REDIS_TOPOLOGY: RedisTopology = RedisTopology::Standalone;
REDIS_CONNECTION_TYPE: RedisConnectionType = RedisConnectionType::Pooled;
REDIS_CACHE_LOCKING_STRATEGY: CacheLockingStrategy = CacheLockingStrategy::Local;
// URL(s) for Redis. Use comma-separated values for multiple URLs in Cluster topology.
REDIS_URL: String = "redis://localhost";
// Configures the waiting timeout for Redis connection *pools*.
// This doesn't affect the bulk of Redis work in Multiplexed connection type.
REDIS_WAIT_TIMEOUT_MS: u64 = 15000u64;
// Minimum and maximum number of connections when Redis is in Standalone topology.
REDIS_MAX_CONNECTIONS: u32 = 2048u32;
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;
// Minimum and maximum number of connections when Redis is in Cluster topology, Pooled connection type.
REDIS_CLUSTER_MAX_CONNECTIONS: u32 = 16u32;
REDIS_CLUSTER_MIN_CONNECTIONS: usize = 0usize;
// The maximum number of connections of the Redis blocking pool. There's a blocking pool regardless of topology
// and main connection type.
REDIS_BLOCKING_MAX_CONNECTIONS: u32 = 256u32;
// The encoding format used for Redis cache values.
REDIS_ENCODING_FORMAT: xredis::EncodingFormat = xredis::EncodingFormat::Json;
// The level of LZ4 compression used for Redis cache values. A value of 0 disables compression (supports 1-12)
REDIS_COMPRESSION_LEVEL: i32 = 0i32;
// The compression algorithm used for Redis cache values. Currently only LZ4 is supported.
REDIS_COMPRESSION_ALGORITHM: xredis::Codec = xredis::Codec::Lz4;
// The minimum number of bytes required to trigger compression for Redis cache values.
REDIS_COMPRESSION_THRESHOLD_BYTES: usize = 1024usize;
// The minimum savings ratio required to trigger compression for Redis cache values. If the savings ratio is lower than this,
// the compressed payload is discarded and the original payload is stored as-is.
REDIS_COMPRESSION_MIN_SAVINGS_RATIO: f64 = 12.5f64;
REDIS_READ_REPLICA_STRATEGY: ReadReplicaStrategy = ReadReplicaStrategy::Primary;
KAFKA_BOOTSTRAP_SERVERS: StringCsv = StringCsv(vec!["localhost:19092".into()]);
KAFKA_CLIENT_ID: String = "labrinth";
BIND_ADDR: String = "";
@@ -292,19 +339,6 @@ vars! {
READONLY_DATABASE_MIN_CONNECTIONS: u32 = 0u32;
READONLY_DATABASE_MAX_CONNECTIONS: u32 = 1u32;
REDIS_WAIT_TIMEOUT_MS: u64 = 15000u64;
REDIS_MAX_CONNECTIONS: u32 = 10000u32;
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_COMPRESSION_LEVEL: i32 = 0i32;
REDIS_COMPRESSION_ALGORITHM: crate::database::redis::Codec = crate::database::redis::Codec::Lz4;
REDIS_COMPRESSION_THRESHOLD_BYTES: usize = 1024usize;
REDIS_COMPRESSION_MIN_SAVINGS_RATIO: f64 = 12.5f64;
SEARCH_OPERATION_TIMEOUT: u64 = 300000u64;
SMTP_REPLY_TO_NAME: String = "";