Configuring Redis Object Cache for WordPress | VORONOV Solutions

Redis Object Cache for WordPress and WooCommerce is a server-side caching technique that stores SQL query results, options objects, and transients in Random Access Memory (RAM). It solves the high latency (TTFB) issue on dynamic pages where static page caching does not work: in the cart, on the checkout page, and in the user account area.

Why Static Cache Does Not Work in WooCommerce and How Redis Helps

Why Static Cache Doesn't Work in WooCommerce and How Redis Helps — VORONOV Solutions

For most WordPress informational pages, standard HTML caching (for example, via Nginx FastCGI Cache, LiteSpeed, or NGINX/WP Rocket plugins) is sufficient. However, for WooCommerce online stores, this approach has significant limitations. According to official WooCommerce recommendations, endpoints such as /cart/, /checkout/ and sessions of authorized buyers are fundamentally not subject to static caching, as they display personalized data.

When a user adds an item to the cart, every click generates dozens of complex SQL queries to the MySQL database (product metadata, stock levels, discount rules, sessions). Without object caching, the database becomes a bottleneck, causing server response delays (TTFB > 1–2 seconds), which directly degrades user behavior metrics. We wrote more about this in our article on how website loading speed affects SEO and sales.

According to the WordPress WP_Object_Cache documentation, wordpress object caching is designed to intercept repeated database requests. Redis stores processed PHP objects directly in RAM, serving them in fractions of a millisecond.

Interaction Architecture: PHP-FPM, Redis, and MySQL

Interaction Architecture: PHP-FPM, Redis, and MySQL — VORONOV Solutions

The request lifecycle with Redis enabled looks as follows:

  1. User request: The browser requests a dynamic page (e.g., the cart).
  2. Cache check: The PHP script via the object cache drop-in (object-cache.php) checks Redis for the required objects.
  3. Cache Hit: If data is found in RAM, it is immediately returned to PHP. No query is executed against MySQL.
  4. Cache Miss: If data is missing, PHP queries MySQL, receives the result, writes it to Redis for future requests, and returns the response to the user.

Connection Configuration: Unix Domain Sockets vs TCP/IP

When configuring Redis on the same server where the website is hosted (localhost), using a TCP/IP network socket creates unnecessary operating system overhead. Redis configuration documentation recommends using Unix domain sockets for local connections, which significantly reduces overhead when performing redis server setup.

Parameter TCP/IP (127.0.0.1:6379) Unix Socket (/var/run/redis/redis-server.sock)
Latency Higher (passes through the network stack) Minimal (inter-process communication IPC)
Throughput Limited by the TCP stack 15–30% higher for local processes
Security Requires firewall/bind configuration Secured by file system access permissions

1. Configuration in redis.conf

unixsocket /var/run/redis/redis-server.sock
unixsocketperm 770
# Disable TCP if Redis runs purely locally
port 0

Make sure that user www-data (or PHP-FPM user) is added to the group redis to grant read and write permissions to the socket.

2. Configuration in wp-config.php

To ensure the Redis Object Cache plugin in WordPress connects correctly via a Unix socket, add the following directives to your site's configuration file:

// Redis connection settings via Unix Socket
define('WP_REDIS_SCHEME', 'unix');
define('WP_REDIS_PATH', '/var/run/redis/redis-server.sock');
define('WP_REDIS_DATABASE', 0); // Redis database index

RAM Management: maxmemory and Eviction Policies

If Redis runs out of allocated RAM without an explicitly defined eviction policy, it will start returning data retrieval errors (OOM command not allowed). According to Redis key eviction documentation, it is critical for WordPress and WooCommerce to properly configure maxmemory-policy.

Recommended configurations in redis.conf:

maxmemory 512mb # Allocated amount depending on server RAM
maxmemory-policy allkeys-lru
  • allkeys-lru: Removes the least recently used (LRU) keys out of all existing keys. The best choice for standard WordPress object cache.
  • volatile-lru: Removes keys with an expiration time (TTL) set. Suitable if Redis is used simultaneously for extended persistent storage.

Key Isolation: Multisite and multiple projects on a single server

A common mistake when running multiple WordPress sites on a single server with a single Redis instance is the lack of keyspace separation. This leads to Site A retrieving content or configuration from Site B.

To avoid key collisions, be sure to set a unique salt in the file wp-config.php for each site:

define('WP_CACHE_KEY_SALT', 'site1_prod_8f3a_');

Troubleshooting WooCommerce: stale cache, stock levels, and race conditions

During high-volume sales or promotions, there is a risk of race conditions, where multiple buyers place an order for the same item simultaneously. If the stock object cache is invalidated with a delay, the buyer sees the item in stock even though it is already out of stock.

Key MySQL and Redis database optimization steps for WooCommerce:

  • Excluding non-persistent groups: Ensure that WooCommerce sessions and cart transients are not cached indefinitely. Plugins should add counts, wc_session_id and transient to the WP_REDIS_IGNORED_GROUPS list as needed.
  • Clearing WooCommerce Redis cache during import: If you update stock quantities or prices via CSV/REST API, built-in WordPress hooks do not always trigger `wp_cache_delete`. Use automated cache clearing scripts after bulk updates complete.
  • Fragmentation monitoring: Monitor the parameter used_memory_rss in the CLI (command redis-cli info memory) to ensure there are no memory leaks.

Redis Object Cache Implementation Checklist

Step Action Goal
1 MySQL Load Check Determine if queries to `wp_options` and meta tables are blocking.
2 Unix Socket Configuration Switch the connection from TCP (127.0.0.1) to a socket to reduce latency.
3 Key Isolation (`WP_CACHE_KEY_SALT`) Prevent conflicts between projects on the same server.
4 `maxmemory-policy` Configuration Protect Redis from crashing due to an Out Of Memory error.
5 Testing Checkout and Cart Ensure personal data and stock quantities are not cached.

When You Need Professional Server-Side Redis Setup

Setting up Redis for WooCommerce requires a balanced approach: a configuration error can lead to showing other users' carts or incorrect price displays. When choosing extensions, it is worth paying attention to proven solutions — read more about this in our article on how to use plugins safely.

The VORONOV Solutions team provides server optimization services, caching system setup, and comprehensive website optimization on WordPress/WooCommerce. All work is carried out transparently according to our approved rates: in the format of one-off hourly development (€35/hr), hourly packages, or as part of ongoing support via Development Retainer and Website Care.

Frequently Asked Questions (FAQ)

What exactly does Redis Object Cache store, and what remains in MySQL?

Redis Object Cache stores the results of repetitive SQL queries in RAM, option objects (table wp_options), post and product metadata (wp_postmeta), as well as transients. The MySQL database remains the primary and reliable storage location for all data (orders, users, products), while Redis acts as a high-speed read buffer.

What is the difference between the free Redis Object Cache plugin and the Pro version for WooCommerce?

The free version implements basic `WP_Object_Cache` functionality and is suitable for most standard websites. The Pro version includes specialized optimization for WooCommerce: Fast-Events support, improved cache invalidation for product stock, real-time query analytics, and protection against race conditions during peak loads.

How to properly clear the Redis cache in WooCommerce after a bulk product import?

During bulk imports via CSV or API, it is recommended to temporarily disable the object cache or perform a reset via WP-CLI after completing the procedure using the command wp cache flush. This ensures that customers will immediately see up-to-date prices and product availability without the risk of reading stale objects from RAM.