Back to Knowledge Hub

    What is Redis aof-use-rdb-preamble and How Does It Work?

    Redis Configuration
    AOF Persistence
    RDB Persistence
    Hybrid Persistence
    Data Safety

    What is aof-use-rdb-preamble?

    aof-use-rdb-preamble is a key configuration option introduced in Redis 4.0 (enabled by default since 7.0+) that implements hybrid persistence by combining RDB snapshots and AOF logs.

    # Redis 7.0+ default configuration (recommended for production)
    aof-use-rdb-preamble yes
    

    Why Use Hybrid Persistence?

    Traditional Persistence Limitations

    AspectRDBAOFHybrid Mode
    Recovery SpeedFast (seconds)Slow (minutes)Fast (seconds)
    Data SafetyMinutes of loss≤1 second loss≤1 second loss
    File SizeSmall (compressed)Large (text logs)Medium (RDB+AOF)
    Write ImpactLowHighMedium

    Three Core Advantages

    1. Lightning-Fast Recovery

    • RDB Binary Loading: 5-10x faster than pure AOF text parsing
    • Benchmark Data: 1GB data recovers in 2-5s (vs 30-60s with pure AOF)

    2. Dual Data Protection

    • Point-in-Time Snapshots: RDB ensures base data integrity
    • Operation Log Tracking: AOF records every data change

    3. Intelligent Storage Management

    Data TypePure AOF SizeHybrid Mode SizeSavings
    String Key-Value100MB60MB40%
    Hash Data500MB280MB44%
    Sorted Set800MB450MB43.75%
    # Compression configurations
    rdbcompression yes                      # RDB compression (default)
    aof-rewrite-incremental-fsync yes       # AOF incremental fsync
    

    How Hybrid Persistence Works

    Redis Hybrid Persistence Architecture

    Core Workflow

    1. Write Handling Phase

    • Client Requests: Process SET/INCR write operations
    • Memory Execution: Update in-memory data immediately
    • Dual Logging:
      • Write to AOF buffer (text format)
      • Periodically generate RDB snapshots (binary format)

    2. Persistence Trigger Phase

    • Initial Trigger:
      • Manual BGSAVE command
      • Reaching save thresholds (e.g., 1 write in 900s)
    • Subsequent Triggers:
      • Append AOF after each write
      • AOF file reaches size threshold (default 4GB)

    3. File Construction Phase

    • RDB Header:
      File Header Structure:
      REDIS0009        # RDB version identifier
      FE 00           # Database selector
      FB              # Hash table size indicator
      0000000000000000 # Key-value data
      
    • AOF Log Appending:
      *3\r\n$3\r\nSET\r\n$5\r\nkey01\r\n$7\r\nvalue01\r\n
      *2\r\n$4\r\nINCR\r\n$7\r\ncounter\r\n
      

    4. Data Recovery Phase

    • Priority Order:
      1. Load latest RDB snapshot
      2. Replay AOF logs sequentially
    • Optimizations:
      • Multi-threaded RDB loading
      • Batch AOF command execution

    File Structure Example

    Hybrid File Structure:
    ┌───────────────────┐
    │   RDB Header      │ ← Binary snapshot
    ├───────────────────┤
    │   AOF Log Entries │ ← Text-based operations
    │   SET key1 value1 │
    │   INCR counter    │
    │   ...             │
    └───────────────────┘
    

    Production Configuration

    Recommended Settings

    # Enable AOF
    appendonly yes
    
    # Enable hybrid mode
    aof-use-rdb-preamble yes
    
    # Optimize rewrite triggers
    auto-aof-rewrite-percentage 100  
    auto-aof-rewrite-min-size 4gb    
    
    # Performance tuning
    aof-rewrite-incremental-fsync yes
    

    Common Issues & Solutions

    1. Configuration Validation

    # Method 1: Check file header
    head -c 5 appendonly.aof
    # Should output "REDIS"
    
    # Method 2: CLI verification
    127.0.0.1:6379> CONFIG GET aof-use-rdb-preamble
    

    2. File Corruption Recovery

    # Step-by-step recovery
    redis-check-rdb --fix appendonly.aof  # Fix RDB section
    redis-check-aof --fix appendonly.aof  # Fix AOF section
    redis-server --appendonly yes --appendfilename appendonly.aof
    

    Performance Optimization

    1. Capacity Planning:

      • Reserve 2x memory as disk space
      • Keep individual AOF files under 16GB
    2. Key Metrics Monitoring:

      # Persistence latency
      redis-cli info persistence | grep aof_delayed_fsync
      
      # File size monitoring
      watch -n 1 "ls -lh appendonly.aof"
      

    Related Content: