pub async fn initialize_redis_connections(
config: &ServerConfig,
) -> Result<Arc<RedisConnections>>Expand description
Initializes Redis connection pools for both primary and reader endpoints.
§Arguments
config- The server configuration containing Redis URLs and pool settings.
§Returns
A RedisConnections struct containing:
primary_pool: Connected toREDIS_URL(for write operations)reader_pool: Connected toREDIS_READER_URLif set, otherwise same as primary
§Features
- Read/Write Separation: When
REDIS_READER_URLis configured, read operations can be distributed across read replicas, reducing load on the primary. - Backward Compatible: If
REDIS_READER_URLis not set, both pools use the primary URL, maintaining existing behavior. - Connection Pooling: Both pools use deadpool-redis with configurable max size, wait timeout, and connection timeouts.
§Example Configuration
# AWS ElastiCache with read replicas
REDIS_URL=redis://my-cluster.xxx.cache.amazonaws.com:6379
REDIS_READER_URL=redis://my-cluster-ro.xxx.cache.amazonaws.com:6379