Infrastructure

How to configure Redis for a high-traffic WooCommerce store

Binadit Engineering · Apr 18, 2026 · 7 min lesen
How to configure Redis for a high-traffic WooCommerce store

Redis caching can dramatically reduce database load and page response times for WooCommerce stores, but only when configured properly for e-commerce workloads. This guide covers the complete setup process, from installation to production optimization, ensuring your store performs well under traffic spikes.

Prerequisites and assumptions

Before starting, you'll need:

  • WooCommerce store running on a VPS or dedicated server
  • Root or sudo access to the server
  • Basic familiarity with SSH and command-line tools
  • At least 2GB RAM available for Redis (4GB+ recommended for high-traffic stores)
  • WordPress with WooCommerce already installed

This guide assumes you're running Ubuntu 20.04 or 22.04, though the concepts apply to other Linux distributions with minor command variations.

Installing and configuring Redis server

Start by installing Redis from the official repository:

sudo apt update
sudo apt install redis-server -y

The default Redis configuration isn't suitable for production WooCommerce use. Edit the main configuration file:

sudo nano /etc/redis/redis.conf

Make these critical changes for WooCommerce workloads:

# Set maximum memory limit (adjust based on available RAM)
maxmemory 1gb

# Use allkeys-lru eviction policy for web caching
maxmemory-policy allkeys-lru

# Enable persistence for session data
save 900 1
save 300 10
save 60 10000

# Bind to localhost only for security
bind 127.0.0.1

# Disable protected mode if using localhost only
protected-mode no

# Set reasonable timeout
timeout 300

The allkeys-lru policy is crucial for WooCommerce because it automatically removes least-recently-used keys when memory fills up, keeping frequently accessed product data and session information in cache.

Restart Redis to apply the configuration:

sudo systemctl restart redis-server
sudo systemctl enable redis-server

Installing Redis object cache plugin

WooCommerce needs a WordPress plugin to interface with Redis. The Redis Object Cache plugin by Till Krüss is the most reliable option:

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

Alternatively, install through the WordPress admin interface under Plugins → Add New.

Activate the plugin and navigate to Settings → Redis to enable the object cache. The plugin will create a object-cache.php file in your wp-content directory.

Optimizing Redis for WooCommerce workloads

WooCommerce generates specific types of cache data that benefit from targeted optimization. Add these settings to your wp-config.php file before the "That's all, stop editing!" line:

// Redis configuration for WooCommerce
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_TIMEOUT', 1);
define('WP_REDIS_READ_TIMEOUT', 1);
define('WP_REDIS_DATABASE', 0);

// Increase cache expiration for product data
define('WP_REDIS_MAXTTL', 86400); // 24 hours

Create a custom Redis configuration for WooCommerce-specific optimizations:

sudo nano /etc/redis/woocommerce.conf

Add these WooCommerce-optimized settings:

# Optimize for frequent small reads/writes
tcp-keepalive 60
tcp-backlog 511

# Increase client connection limits
maxclients 10000

# Optimize background saving
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes

# Logging for monitoring
loglevel notice
logfile /var/log/redis/redis-server.log

Include this configuration in the main Redis config:

echo "include /etc/redis/woocommerce.conf" | sudo tee -a /etc/redis/redis.conf

Configuring cache groups for WooCommerce

WooCommerce generates different types of data with varying cache requirements. Configure cache groups by adding this to your theme's functions.php file:

// Optimize WooCommerce cache groups
function optimize_woocommerce_cache_groups() {
    // Long-term caching for product data
    wp_cache_add_global_groups(array(
        'woocommerce-product-meta',
        'woocommerce-attributes',
        'woocommerce-categories'
    ));
    
    // Short-term caching for dynamic content
    wp_cache_add_non_persistent_groups(array(
        'woocommerce-cart',
        'woocommerce-session',
        'woocommerce-checkout'
    ));
}
add_action('init', 'optimize_woocommerce_cache_groups');

This ensures product catalogs stay cached longer while cart and session data remains dynamic per user.

Setting up Redis for session management

WooCommerce sessions can overwhelm databases during high traffic. Configure Redis as the session handler by adding this to wp-config.php:

// Use Redis for WordPress sessions
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://127.0.0.1:6379');
ini_set('session.gc_maxlifetime', 3600); // 1 hour

For better session management, install the WP Redis Session Handler plugin or add this custom session handler to your theme:

class WooCommerce_Redis_Sessions {
    private $redis;
    
    public function __construct() {
        $this->redis = new Redis();
        $this->redis->connect('127.0.0.1', 6379);
        add_action('init', array($this, 'start_session'));
    }
    
    public function start_session() {
        if (!session_id()) {
            session_start();
        }
    }
}

new WooCommerce_Redis_Sessions();

Monitoring Redis performance

Proper monitoring ensures Redis continues performing well as traffic grows. Install Redis monitoring tools:

sudo apt install redis-tools htop iotop

Create a monitoring script to track key metrics:

sudo nano /usr/local/bin/redis-monitor.sh
#!/bin/bash

# Redis performance monitoring for WooCommerce
echo "=== Redis Memory Usage ==="
redis-cli info memory | grep used_memory_human

echo "=== Cache Hit Rate ==="
redis-cli info stats | grep keyspace

echo "=== Connected Clients ==="
redis-cli info clients | grep connected_clients

echo "=== Operations Per Second ==="
redis-cli info stats | grep instantaneous_ops_per_sec

echo "=== Slow Queries ==="
redis-cli slowlog get 5

Make it executable and run regularly:

sudo chmod +x /usr/local/bin/redis-monitor.sh
./redis-monitor.sh

Set up automated monitoring with a cron job:

crontab -e
# Add this line to check Redis every 5 minutes
*/5 * * * * /usr/local/bin/redis-monitor.sh >> /var/log/redis-monitor.log 2>&1

Verification: confirming Redis is working

Test Redis connectivity and basic functionality:

redis-cli ping

You should see PONG as the response.

Check if WordPress is using Redis for object caching:

redis-cli monitor

Load your WooCommerce store in another terminal window. You should see cache operations scrolling in the monitor output.

Verify cache statistics through WordPress admin:

  • Go to Settings → Redis in your WordPress dashboard
  • Check the "Status" shows "Connected"
  • Monitor "Hit Ratio" - aim for 80%+ after the cache warms up
  • Watch "Cache Objects" count increase as pages load

Test performance improvement with these commands:

# Clear all caches first
redis-cli flushall
wp cache flush (if WP-CLI is installed)

# Load test with cache cold
curl -w "@curl-format.txt" -o /dev/null -s http://your-site.com

# Load test with cache warm (run same command again)
curl -w "@curl-format.txt" -o /dev/null -s http://your-site.com

Create the curl-format.txt file for timing measurements:

echo "Response time: %{time_total}s\nConnect time: %{time_connect}s\nFirst byte: %{time_starttransfer}s" > curl-format.txt

You should see significantly faster response times on the second (cached) request.

Common pitfalls to avoid

Several configuration mistakes can reduce Redis effectiveness:

Memory limits too low: WooCommerce stores need sufficient memory for product catalogs, session data, and page cache. Monitor memory usage and increase the maxmemory setting if you see frequent evictions.

Wrong eviction policy: Using noeviction or volatile-lru can cause cache failures. Stick with allkeys-lru for WooCommerce workloads.

Caching user-specific data globally: Never cache cart contents, checkout pages, or account information in shared cache. Use the non-persistent groups configuration shown earlier.

Ignoring persistence settings: WooCommerce session data should persist across Redis restarts. Keep the save directives in your configuration.

No monitoring: Redis performance degrades silently. Regular monitoring catches issues before they impact customers.

Performance tuning for high traffic

As traffic increases, additional optimizations become necessary. For stores handling thousands of concurrent users, consider these advanced configurations.

Increase Redis's TCP backlog for more concurrent connections:

# In /etc/redis/redis.conf
tcp-backlog 2048
# Also increase system limit
echo "net.core.somaxconn = 2048" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Configure multiple Redis databases for different cache types:

# WordPress object cache
define('WP_REDIS_DATABASE', 0);

# Sessions (requires custom configuration)
define('WC_SESSION_CACHE_GROUP', 'wc_session_cache');
define('WC_SESSION_REDIS_DATABASE', 1);

This separation prevents cache conflicts and allows independent tuning of each database.

For extremely high traffic, consider Redis clustering or running separate Redis instances for different cache types. However, most WooCommerce stores will find the single-instance configuration sufficient when properly tuned.

Proper Redis configuration transforms WooCommerce performance under load, but it's just one component of a complete infrastructure strategy. Preparing your WooCommerce store for peak traffic events requires additional considerations beyond caching, while optimizing database performance addresses the backend systems that Redis helps protect.

Next steps and related reading

With Redis configured and running, consider these additional optimizations:

  • Set up Redis Sentinel for high availability in production
  • Implement Redis monitoring with tools like RedisInsight or Grafana
  • Configure PHP OPcache to complement Redis object caching
  • Set up CDN integration for static assets
  • Implement database query optimization for uncached operations

Monitor your Redis instance regularly and adjust memory limits as your product catalog and traffic grow. The configuration provided here handles most WooCommerce workloads effectively, but every store has unique patterns that may benefit from custom tuning.

Redis configuration is one element of comprehensive infrastructure management. Stores experiencing rapid growth often benefit from cloud cost optimization services that balance performance requirements with operational efficiency, ensuring infrastructure scales cost-effectively with business needs.

Need this running in production without building it yourself? See our managed infrastructure services or schedule a call.