Function initialize_redis_connections

Source
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 to REDIS_URL (for write operations)
  • reader_pool: Connected to REDIS_READER_URL if set, otherwise same as primary

§Features

  • Read/Write Separation: When REDIS_READER_URL is configured, read operations can be distributed across read replicas, reducing load on the primary.
  • Backward Compatible: If REDIS_READER_URL is 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