DEV Community

Cover image for How to configure Redis for a high-traffic WooCommerce store
binadit
binadit

Posted on • Originally published at binadit.com

How to configure Redis for a high-traffic WooCommerce store

Scaling WooCommerce with Redis: A production-ready caching strategy

When your WooCommerce store starts getting serious traffic, database queries become the bottleneck that kills performance. I've seen stores crawl to a halt during flash sales because every product view triggers multiple database hits. Redis object caching solves this, but most tutorials skip the WooCommerce-specific optimizations that make the real difference.

System requirements

Before diving in, ensure you have:

  • Ubuntu 20.04+ server with root access
  • 4GB+ RAM (minimum 2GB for Redis alone)
  • Active WooCommerce installation
  • SSH access and basic command line skills

Redis server installation and base config

Install Redis from the official repository:

sudo apt update && sudo apt install redis-server -y
Enter fullscreen mode Exit fullscreen mode

The default configuration won't handle WooCommerce workloads. Edit the main config:

sudo nano /etc/redis/redis.conf
Enter fullscreen mode Exit fullscreen mode

Apply these production settings:

# Memory management for WooCommerce
maxmemory 2gb
maxmemory-policy allkeys-lru

# Data persistence for sessions
save 900 1
save 300 10
save 60 10000

# Security and timeouts
bind 127.0.0.1
protected-mode no
timeout 300
Enter fullscreen mode Exit fullscreen mode

The allkeys-lru policy is critical here. It automatically evicts old data when memory fills up, keeping hot product data and active sessions cached.

sudo systemctl restart redis-server
sudo systemctl enable redis-server
Enter fullscreen mode Exit fullscreen mode

WordPress Redis integration

Install the Redis Object Cache plugin:

cd /var/www/your-site/wp-content/plugins
wget https://downloads.wordpress.org/plugin/redis-cache.latest-stable.zip
unzip redis-cache.latest-stable.zip
chown -R www-data:www-data redis-cache
Enter fullscreen mode Exit fullscreen mode

Activate through WordPress admin, then configure in wp-config.php:

// Redis connection settings
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_TIMEOUT', 1);
define('WP_REDIS_DATABASE', 0);
define('WP_REDIS_MAXTTL', 86400); // 24h for product data
Enter fullscreen mode Exit fullscreen mode

WooCommerce-specific optimizations

Create targeted cache groups in your theme's functions.php:

function setup_woocommerce_cache_groups() {
    // Cache product data aggressively
    wp_cache_add_global_groups([
        'woocommerce-product-meta',
        'woocommerce-attributes',
        'woocommerce-categories'
    ]);

    // Keep user data dynamic
    wp_cache_add_non_persistent_groups([
        'woocommerce-cart',
        'woocommerce-session',
        'woocommerce-checkout'
    ]);
}
add_action('init', 'setup_woocommerce_cache_groups');
Enter fullscreen mode Exit fullscreen mode

This ensures product catalogs stay cached while cart data remains per-user.

Session management through Redis

Move WooCommerce sessions from database to Redis by adding to wp-config.php:

// Redis session handling
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://127.0.0.1:6379');
ini_set('session.gc_maxlifetime', 3600);
Enter fullscreen mode Exit fullscreen mode

Performance monitoring setup

Create a monitoring script to track Redis health:

sudo nano /usr/local/bin/redis-health.sh
Enter fullscreen mode Exit fullscreen mode
#!/bin/bash
echo "Memory: $(redis-cli info memory | grep used_memory_human)"
echo "Hit Rate: $(redis-cli info stats | grep keyspace_hits)"
echo "Clients: $(redis-cli info clients | grep connected_clients)"
echo "Ops/sec: $(redis-cli info stats | grep instantaneous_ops_per_sec)"
Enter fullscreen mode Exit fullscreen mode
sudo chmod +x /usr/local/bin/redis-health.sh
Enter fullscreen mode Exit fullscreen mode

Verification and testing

Test Redis connectivity:

redis-cli ping  # Should return PONG
Enter fullscreen mode Exit fullscreen mode

Monitor cache activity:

redis-cli monitor
Enter fullscreen mode Exit fullscreen mode

Then load your store in another terminal to see cache operations.

Performance test with timing:

# Cold cache
redis-cli flushall
curl -w "Total: %{time_total}s\n" -o /dev/null -s http://your-store.com

# Warm cache (run again)
curl -w "Total: %{time_total}s\n" -o /dev/null -s http://your-store.com
Enter fullscreen mode Exit fullscreen mode

You should see 50-80% faster response times with warm cache.

Critical mistakes to avoid

Memory limits too low: WooCommerce needs significant memory for product catalogs and session data. Monitor usage and adjust accordingly.

Wrong eviction policy: Never use noeviction with WooCommerce. Stick with allkeys-lru.

Caching user-specific data: Cart contents and checkout pages should never be cached globally. The cache groups configuration prevents this.

Ignoring monitoring: Set up automated alerts when cache hit rates drop below 80% or memory usage exceeds 90%.

Results you can expect

Properly configured Redis typically delivers:

  • 2-5x faster page load times
  • 70-90% reduction in database queries
  • Improved server stability during traffic spikes
  • Better user experience with faster cart operations

The key is WooCommerce-specific tuning, not just generic Redis caching. Product data benefits from long-term caching while user sessions need careful isolation.

Originally published on binadit.com

Top comments (0)