Object Caching with Redis in WordPress: Configuration and Optimization
Speed up your WordPress site with Redis object caching: reduce slow MySQL database queries and optimize your website's speed.
When a WordPress site grows in terms of its catalog, concurrent visitors, or registered users, the MySQL database usually becomes the first bottleneck. Even if you use page caching, every dynamic query forces the server to read the same tables over and over again.
In this guide, you'll learn how object caching works with Redis, in which scenarios it actually reduces response times, how to configure it correctly, and which metrics to monitor to avoid memory issues or outdated data.
In this guide:
- Difference Between Page Cache and Persistent Object Cache
- Which MySQL Queries Does Redis Reduce in WordPress?
- Where Does Redis Make the Biggest Difference?
- Step-by-Step Guide to Enabling and Configuring Redis in WordPress
- How to Check Performance and Measure the Hit Ratio
- Advanced Optimization: Outdated Memory and Cache Policies
Difference Between Page Cache and Persistent Object Cache
WordPress includes the class by default WP_Object_Cache, but without a persistent engine, that memory only lasts as long as it takes to generate a single HTTP request. When the next visitor loads the same view, PHP queries MySQL again from scratch.
The page cache stores the final HTML for anonymous visitors, while Redis adds a persistent in-memory layer that caches PHP and SQL query results across different requests. In addition, both layers are complemented by edge delivery, as we explain in our guide on What Is a CDN for Your Website?.
| Cache layer | What it stores | Where does it accelerate the most? | Main Limit |
|---|---|---|---|
| Page Cache | Fully rendered HTML | Anonymous visitors to posts and public pages | Omitted for shopping carts, checkouts, and logged-in users |
| Object Cache (Redis) | SQL Query Results, PHP Options, and Objects | Panel wp-admin, WooCommerce, filters, and sessions |
Requires controlled RAM and consistent cleaning |
| Disk Storage | MySQL Files, Images, and Physical Tables | Uncached reads and actual writes | Slower than RAM, even with NVMe storage |
Which MySQL Queries Does Redis Reduce in WordPress?
Every time a page is loaded without caching, WordPress queries dozens or hundreds of records to build menus, permissions, plugin settings, and product data. By connecting Redis—an in-memory data structure store documented in the official Redis documentation—, PHP reads those objects from RAM in fractions of a millisecond.
- Options with autoload in
wp_options: It avoids having to check the global settings for themes and plugins with every request. - WordPress Transients: It caches temporary responses from external APIs, widgets, or resource-intensive queries outside the database.
- WooCommerce Sessions and Metadata: streamlines the calculation of shopping carts, coupons, inventory changes, and order inquiries.
- Surgery on
wp-admin: Speeds up product listings, product filters, and simultaneous editing when multiple team members are working at the same time.
Where Does Redis Make the Biggest Difference?
Not all sites see the same improvement. On a simple corporate website where 95% of the traffic consists of anonymous visitors served from the page cache, Redis is most helpful for managing the internal dashboard, but visitors rarely reach the PHP layer.
On the other hand, the improvement in stability is evident in WooCommerce stores with high concurrent traffic, online academies, directories with dynamic filters, and membership portals. If you notice increasing slowness in the admin panel or CPU spikes in MySQL, you should also evaluate whether Your current hosting plan isn't enough in dedicated resources.
Step-by-Step Guide to Enabling and Configuring Redis in WordPress
To enable Redis with command-line support, you need the service to be available on the server and to link it using a drop-in file. object-cache.php inside wp-content/. Follow this sequence:
- Enable the Redis service on your hosting account: confirms the UNIX socket or the local host (
127.0.0.1and port6379) along with the PHP extensionphpredisactive. In the Managed Hosting from UNEMPRENDE This feature is enabled directly at the environment level. - Define isolation constants in
wp-config.php: Before activating the plugin, add a unique prefix for each installation and set short timeouts so that a cache restart never blocks PHP. - Install and activate the connector: Install a Redis-compatible object cache plugin, then click Enable Object Cache and confirms that the status changes to "connected.".
- Test the site in a private window and in
wp-admin: Shopping cart testing, forms, login, and saving entries.
Recommended constants in wp-config.php
define( 'WP_REDIS_PREFIX', 'mycompany_prod_' );Prevents key collisions if there are multiple sites or a staging environment on the same server.define( 'WP_REDIS_TIMEOUT', 1 );ydefine( 'WP_REDIS_READ_TIMEOUT', 1 );limit the wait time in the event of unexpected delays.define( 'WP_REDIS_DATABASE', 0 );assigns a specific logical base when the server manages multiple instances.
How to Check Performance and Measure the Hit Ratio
Enabling Redis without measuring its performance leaves you in the dark. Install it temporarily Query Monitor Or check the Redis connector's metrics dashboard to compare three specific metrics before and after:
- Hit ratio: Percentage of objects found in RAM without having to access MySQL. On a stable site, this figure is typically above 90% after the initial loads.
- Number of SQL queries per page: in dynamic catalog views or
wp-admin, you should see a sharp drop compared to the previous state. - PHP Generation Time (TTFB): Compare the time to the first byte on uncached pages, such as the shopping cart or the customer's account.
Advanced Optimization: Outdated Memory and Cache Policies
Two common oversights can ruin a good Redis configuration: forgetting to set the memory limit and failing to clear the cache after making changes outside of WordPress.
Eviction Policy and Memory Limit
Always set a limit maxmemory based on the server's RAM and uses an eviction policy such as allkeys-lru o volatile-lru. If you leave politics in noeviction and when Redis fills its allocated memory, it will begin to reject new writes, and errors will appear on the screen.
How to Prevent Outdated Cache and Inflated Keys
If you modify data directly using SQL, import a database, or migrate the site, clear the object cache using Flush WP Cache or from the plugin dashboard to remove obsolete references. Also, periodically check the size of your rows autoload in wp_options: Redis speeds up reads, but keeping the table clean prevents wasting megabytes of RAM on every request.
You might also be interested in Tutorials
Resources and Support
We offer a variety of resources to help you become familiar with and understand your resources and opportunities, and to enjoy the benefits of having a digital infrastructure. In addition, we have social programs to support startups and projects with exclusive benefits.
