chore(flags): Align Redis config with Django pattern (#41222)

This commit is contained in:
Phil Haack
2025-11-11 08:37:35 -08:00
committed by GitHub
parent 4eed5e85b6
commit 7fcfb70be2
3 changed files with 10 additions and 22 deletions

View File

@@ -296,17 +296,15 @@ services:
MAXMIND_DB_PATH: '/share/GeoLite2-City.mmdb'
# Shared Redis for non-critical path (analytics, billing, cookieless)
REDIS_URL: 'redis://redis:6379/'
# Optional: Use separate Redis URLs for read/write separation
# Optional: Use separate Redis URL for read replicas
# REDIS_READER_URL: 'redis://redis-replica:6379/'
# REDIS_WRITER_URL: 'redis://redis-primary:6379/'
# Optional: Increase Redis timeout (default is 100ms)
# REDIS_TIMEOUT_MS: 200
# Dedicated Redis database for critical path (team cache + flags cache)
# Hobby deployments start in Mode 1 (shared-only). Developers override in docker-compose.dev.yml for Mode 2.
# FLAGS_REDIS_URL: 'redis://redis:6379/1'
# Optional: Use separate Flags Redis URLs for read/write separation
# Optional: Use separate Flags Redis URL for read replicas
# FLAGS_REDIS_READER_URL: 'redis://redis-replica:6379/1'
# FLAGS_REDIS_WRITER_URL: 'redis://redis-primary:6379/1'
ADDRESS: '0.0.0.0:3001'
RUST_LOG: 'info'
COOKIELESS_REDIS_HOST: redis7

View File

@@ -193,9 +193,6 @@ pub struct Config {
#[envconfig(default = "")]
pub redis_reader_url: String,
#[envconfig(default = "")]
pub redis_writer_url: String,
// Dedicated Redis for feature flags (critical path: team cache + flags cache)
// When empty, falls back to shared Redis URLs above
#[envconfig(default = "")]
@@ -204,9 +201,6 @@ pub struct Config {
#[envconfig(default = "")]
pub flags_redis_reader_url: String,
#[envconfig(default = "")]
pub flags_redis_writer_url: String,
// Controls whether to read from dedicated Redis cache
// false = Mode 2: dual-write to both caches, read from shared (warming phase)
// true = Mode 3: read and write dedicated Redis only (cutover complete)
@@ -465,10 +459,8 @@ impl Config {
address: SocketAddr::from_str("127.0.0.1:0").unwrap(),
redis_url: "redis://localhost:6379/".to_string(),
redis_reader_url: "".to_string(),
redis_writer_url: "".to_string(),
flags_redis_url: "".to_string(),
flags_redis_reader_url: "".to_string(),
flags_redis_writer_url: "".to_string(),
flags_redis_enabled: FlexBool(false),
write_database_url: "postgres://posthog:posthog@localhost:5432/test_posthog"
.to_string(),
@@ -558,11 +550,7 @@ impl Config {
}
pub fn get_redis_writer_url(&self) -> &str {
if self.redis_writer_url.is_empty() {
&self.redis_url
} else {
&self.redis_writer_url
}
&self.redis_url
}
/// Get the Redis URL for flags cache reads (critical path: team cache + flags cache)
@@ -580,9 +568,7 @@ impl Config {
/// Get the Redis URL for flags cache writes (critical path: team cache + flags cache)
/// Returns None if dedicated flags Redis is not configured
pub fn get_flags_redis_writer_url(&self) -> Option<&str> {
if !self.flags_redis_writer_url.is_empty() {
Some(&self.flags_redis_writer_url)
} else if !self.flags_redis_url.is_empty() {
if !self.flags_redis_url.is_empty() {
Some(&self.flags_redis_url)
} else {
None

View File

@@ -50,8 +50,12 @@ where
{
// Configure compression based on environment variable
let compression_config = if *config.redis_compression_enabled {
tracing::info!("Redis compression enabled");
CompressionConfig::default()
let config = CompressionConfig::default();
tracing::info!(
"Redis compression enabled (threshold: {} bytes)",
config.threshold
);
config
} else {
tracing::info!("Redis compression disabled");
CompressionConfig::disabled()