DevOps

Redis Object Cache: Complete Guide for WordPress on Linux VPS

redis object cache
On this page

A Redis object cache stores frequently used WordPress data in memory so it can be retrieved without repeatedly querying the database. On a Linux VPS, Redis can reduce database work and improve response times for dynamic WordPress requests.

This guide explains how Redis object caching works, how to install Redis on a Linux VPS, connect it to WordPress, configure it with LiteSpeed Cache, monitor it, and troubleshoot common problems.

What Is a Redis Object Cache?

A Redis object cache is a persistent caching layer that stores WordPress objects in Redis instead of keeping them only in PHP memory for the duration of a single request.

WordPress uses its object cache to store data such as results from expensive database queries. By default, the WordPress object cache is non-persistent, so its contents normally disappear when the request ends. A persistent object cache allows cached objects to remain available between requests.

Redis is well suited to this job because it keeps frequently accessed data in memory.

The basic flow looks like this:

WordPress

Check object cache

Redis

Cache hit → Return cached data

Cache miss

MySQL/MariaDB

Return data → Store result in Redis

This does not replace your WordPress database. Redis works alongside it.

Does Redis Object Caching Make WordPress Faster?

Yes, but the improvement depends on how your WordPress site works.

Redis is most useful when WordPress repeatedly needs data that can be cached between requests. This is especially helpful for dynamic pages, logged-in users, WooCommerce stores, busy dashboards, and sites with database-intensive plugins.

However, Redis is not a replacement for full page caching.

LiteSpeed Cache can serve a cached page without invoking PHP at all. In that situation, WordPress may not need to query Redis because the request never reaches the application layer. Object caching becomes more useful when WordPress actually has to execute PHP and retrieve data from the database. This layer is vital when you are working to reduce initial server response time in WordPress for dynamic requests.

That means a strong WordPress VPS can use both:

Browser

LiteSpeed Page Cache

If dynamic request

WordPress

Redis Object Cache

MySQL/MariaDB

Redis Object Caching vs WordPress Page Caching

These two caching systems solve different problems.

FeaturePage CacheRedis Object Cache
Main purposeCache complete pagesCache application data
Works before PHPYesNo
Reduces PHP executionYesNo
Reduces database queriesIndirectlyDirectly
Useful for logged-in usersLimitedOften useful
Useful for dynamic requestsLimitedYes
Stores data in memoryUsually notYes
WordPress database still neededYesYes

A page cache can avoid WordPress processing entirely for a cacheable request.

Redis works deeper inside WordPress. It helps when WordPress needs to retrieve objects while generating a response.

What Does Redis Object Caching Store?

WordPress can cache many types of data through its object cache API.

Examples include:

  • Database query results
  • WordPress options
  • User-related data
  • Metadata
  • Taxonomy information
  • Transients
  • Plugin-generated objects
  • Frequently requested application data

The exact objects stored depend on WordPress, plugins, themes, and the object cache implementation.

You should not assume that every database query automatically becomes a Redis key. WordPress and individual plugins decide what is placed into the object cache.

How Does Redis Object Caching Work in WordPress?

WordPress communicates with the persistent object cache through an object-cache.php drop-in inside the wp-content directory.

The Redis Object Cache plugin provides this persistent backend and supports Redis clients such as PhpRedis and Predis.

The request flow becomes:

WordPress Redis Caching Workflow

This is why simply installing the Redis server is not enough. WordPress must also be configured to use Redis as its persistent object cache.

How to Install Redis on a Linux VPS

The following example uses Ubuntu or Debian with the official Redis APT repository.

Step 1: Add the Redis repository

Run:

sudo apt-get install lsb-release curl gpg

This installs the packages needed to add and authenticate the Redis repository.

Add the Redis signing key:

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

Set the correct permissions:

sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg

Add the repository:

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

Update the package index:

sudo apt-get update

Redis documents this installation method for current Ubuntu and Debian systems.

Deploy Your Scalable CyberPanel VPS Server for Free Today!

Step 2: Install Redis

Run:

sudo apt-get install redis

The Redis package includes the Redis server and Redis tools such as redis-cli.

Step 3: Check the Redis service

Run:

sudo systemctl status redis-server

You should see a running service.

If it is not running:

sudo systemctl start redis-server

Enable it at boot:

sudo systemctl enable redis-server

Redis normally starts automatically after installation, but these commands ensure the service starts after a reboot.

How to Test Redis on Your VPS

Before connecting WordPress, test Redis itself.

Run:

redis-cli ping

Output:

PONG

redis-cli is Redis’s command-line utility, and PING is a simple way to verify that the server accepts connections.

You can also enter the Redis CLI:

redis-cli

Then run:

127.0.0.1:6379> PING
PONG

Exit with:

127.0.0.1:6379> exit

If redis-cli ping fails, fix Redis before attempting to configure WordPress.

How to Check Whether PHP Can Use Redis

WordPress needs a PHP Redis client, or another supported Redis client, to communicate with the Redis server.

On Debian or Ubuntu, one common option is the PhpRedis extension.

Install it with:

sudo apt install php-redis

Then check whether PHP can see the extension:

php -m | grep redis

Output:

redis

The PHP version used by your WordPress site must have the Redis extension available. Installing the extension for a different PHP version will not automatically make it available to the PHP process serving your website.

If your VPS uses multiple PHP versions, verify the extension for the specific version assigned to the WordPress site.

How to Set Up Redis Object Cache WordPress

Once Redis is running and PHP can communicate with it, connect WordPress to Redis.

One straightforward option is the Redis Object Cache plugin by Till Krüss. WordPress lists it as a persistent object cache backend powered by Redis.

Step 1: Install the plugin

Using WP-CLI, move into your WordPress installation:

cd /var/www/example.com/public_html

Replace the path with your actual WordPress directory.

Install and activate the plugin:

wp plugin install redis-cache --activate

Step 2: Enable the object cache

Run:

wp redis enable

This enables the persistent object cache drop-in.

The plugin provides several WP-CLI commands, including:

wp redis status
wp redis enable
wp redis disable
wp redis update-dropin

These commands are documented by the plugin project.

Step 3: Check the Redis connection

Run:

wp redis status

The command displays Redis connection and object cache diagnostics.

A healthy setup should report that Redis is connected and the object cache is enabled.

How to Configure Redis in wp-config.php

For a local Redis installation, WordPress can normally connect to:

127.0.0.1:6379

If your setup requires explicit connection settings, add them to wp-config.php before the line:

/* That's all, stop editing! Happy publishing. */

Example:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );

For a server hosting multiple WordPress sites, use a unique cache key prefix or separate Redis databases so that different sites do not accidentally share the same cache namespace.

For example:

define( 'WP_REDIS_DATABASE', 1 );
define( 'WP_CACHE_KEY_SALT', 'example.com:' );

Use a different database or key prefix for another site.

After changing wp-config.php, check its PHP syntax:

php -l wp-config.php

Output:

No syntax errors detected in wp-config.php

How to Configure Redis Object Cache With LiteSpeed Cache

If your WordPress VPS uses LiteSpeed, Redis object caching can complement LiteSpeed’s page caching. Choosing a dedicated WordPress cache plugin designed to utilize server-level architecture ensures your dynamic query results load swiftly.

LiteSpeed Cache for WordPress supports external object caching through Redis. Its Object Cache settings allow you to specify the Redis method, host, port, database ID, lifetime, and other options.

In WordPress, open:

LiteSpeed Cache → Cache → Object

Then configure:

SettingExample
Object CacheON
MethodRedis
Host127.0.0.1
Port6379
Redis Database ID0
Persistent ConnectionON

The exact values depend on your Redis configuration.

If Redis uses a Unix socket instead of TCP, use the socket path and the corresponding port configuration instead.

LiteSpeed also supports a custom object cache prefix, which can help separate cache keys between sites sharing the same Redis service.

Redis Object Cache WordPress With LiteSpeed

The two caching layers should not be confused:

Redis Object Cache WordPress With LiteSpeed
          

If LiteSpeed can serve a page directly from its full page cache, WordPress may not need to execute.

If WordPress must generate the page, Redis can reduce the work required to retrieve frequently used data.

How to Configure Redis Memory Limits

Redis stores cached objects in memory, so a VPS should not allow Redis to consume unlimited RAM.

The maxmemory directive defines the memory limit for Redis data. Redis then uses the configured eviction policy when that limit is reached.

For example:

maxmemory 512mb

The correct value depends on your VPS RAM, WordPress workload, database requirements, PHP workers, and other services.

Do not blindly allocate most of the server’s RAM to Redis.

A VPS running WordPress may also need memory for:

  • PHP workers
  • MySQL or MariaDB
  • LiteSpeed or OpenLiteSpeed
  • Operating system processes
  • File system cache
  • WordPress background tasks

Leave enough RAM for these services.

Which Redis Eviction Policy Should You Use?

When Redis reaches its configured memory limit, the eviction policy determines which keys are removed.

Common policies include:

PolicyBehavior
noevictionReturns errors instead of evicting keys
allkeys-lruRemoves less recently used keys
allkeys-lfuRemoves less frequently used keys
allkeys-randomRemoves random keys
volatile-lruRemoves less recently used keys with an expiration
volatile-lfuRemoves less frequently used keys with an expiration
volatile-ttlRemoves keys with the shortest remaining TTL

Redis documents these policies and their behavior in its eviction documentation.

For a cache-only Redis instance, an eviction policy such as allkeys-lru can be a practical starting point because Redis can remove less recently used cache entries when memory becomes full.

Do not choose an eviction policy without understanding what your Redis instance stores. If Redis is also being used for persistent application data, cache-style eviction may be inappropriate.

How to Configure Redis for a WordPress Cache

For a Redis instance dedicated to WordPress object caching, you can define the memory policy in the Redis configuration file.

The location can vary by distribution and installation method, so first identify the active configuration:

redis-cli CONFIG GET dir

You can also inspect the service configuration and package files on your distribution.

Once you identify the active redis.conf, relevant settings can look like:

maxmemory 512mb
maxmemory-policy allkeys-lru

After changing configuration, restart Redis:

sudo systemctl restart redis-server

Then verify that Redis is responding:

redis-cli ping

Output:

PONG

Redis recommends leaving some memory available when persistence or replication buffers are involved because those buffers are not counted in the same way as cache data for eviction decisions.

Should Redis Persistence Be Enabled for WordPress Object Caching?

Not always.

If Redis is being used only as a disposable WordPress object cache, losing the cached objects normally means WordPress can regenerate them from the database.

Redis persistence is more important when Redis contains data that must survive a restart.

This distinction matters because Redis supports persistence mechanisms such as snapshots and append-only files, but a cache does not necessarily need the same durability requirements as primary application data.

Before changing persistence settings, determine whether Redis contains only cache data.

Do not disable persistence blindly on a Redis server that is also being used for queues, sessions, or application data.

How to Monitor Redis Object Caching

After enabling Redis, monitor whether the cache is actually being used.

Check Redis memory

Run:

redis-cli INFO memory

This shows Redis memory statistics.

For a shorter view:

redis-cli INFO memory | grep used_memory

Check cache statistics

Run:

redis-cli INFO stats

Look for:

keyspace_hits
keyspace_misses
evicted_keys

These metrics help you understand whether Redis is receiving cache requests and whether keys are being evicted.

Check WordPress Redis status

Run:

wp redis status

This is one of the quickest ways to verify the WordPress side of the integration.

Check the object cache directly

WordPress also provides WP-CLI commands for interacting with the object cache:

wp cache

For example:

wp cache get my_key my_group

The WordPress CLI documentation provides commands for adding, retrieving, deleting, and flushing object cache data.

How to Know if Redis Object Caching Is Working

Do not judge Redis only by whether the plugin says “Connected.”

Check three layers:

1. Redis is running

redis-cli ping

2. WordPress is connected

wp redis status

3. Redis is receiving cache activity

redis-cli INFO stats

After visiting the site and performing normal WordPress actions, cache statistics should change.

A connected Redis server with no meaningful cache activity can indicate that the application is not actually using it as expected.

Common Redis Object Cache Problems

Redis connection refused

You may see an error similar to:

Connection refused

Check the Redis service:

sudo systemctl status redis-server

Then test it:

redis-cli ping

If Redis is stopped:

sudo systemctl start redis-server

PHP Redis extension is missing

Check:

php -m | grep redis

If nothing is returned, the PHP process may not have the Redis extension available.

Install the appropriate package for your PHP version and restart the relevant PHP service.

The important point is that the CLI PHP version and the PHP version serving your WordPress site can differ.

WordPress says Redis is connected, but object cache is not enabled

Check:

wp redis status

Then enable the drop-in:

wp redis enable

WordPress persistent object caching relies on the object-cache.php drop-in. Installing a Redis server alone does not activate persistent object caching in WordPress.

The object cache drop-in cannot be created

The Redis Object Cache plugin needs access to the WordPress files to create or update its drop-in.

Check:

ls -la wp-content/object-cache.php

Also verify that the user running WP-CLI has the required permissions.

Do not solve permission problems by making the entire WordPress directory world-writable.

Fix ownership and permissions according to your web server and deployment setup.

Another object cache drop-in already exists

WordPress expects the persistent object cache drop-in at:

wp-content/object-cache.php

If another caching system already controls this file, do not overwrite it without checking what it does.

The Redis Object Cache plugin provides:

wp redis update-dropin

for updating its own drop-in.

First identify which caching system your website is already using.

Redis uses too much memory

Check:

redis-cli INFO memory

Then inspect:

redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy

If Redis has no sensible memory limit, configure one based on the VPS’s total RAM and the requirements of the other services.

Redis supports maxmemory specifically to limit cache data and eviction policies to control what happens when that limit is reached.

Redis keeps evicting keys

Check:

redis-cli INFO stats | grep evicted_keys

A growing eviction count can mean Redis is reaching its configured memory limit.

That does not automatically mean Redis is broken. Cache eviction is expected when a configured eviction policy removes older or less useful keys.

If eviction is excessive, review:

  • Redis memory allocation
  • Object cache size
  • WordPress plugins
  • Cache key growth
  • Cache expiration
  • VPS available RAM

Redis Security Best Practices on a VPS

Do not expose a Redis server directly to the public internet unless you hagve a specific architecture that requires it and have secured the connection appropriately.

For a WordPress site and Redis running on the same VPS, keeping Redis on localhost is usually simpler.

Check the Redis listening configuration and avoid unnecessary public exposure.

A local setup commonly uses:

127.0.0.1:6379

Redis’s own documentation notes that Redis is designed to operate in trusted environments and that authentication and network isolation need to be considered when it is exposed beyond that environment.

Also:

  • Use a firewall.
  • Do not expose port 6379 publicly without a reason.
  • Use authentication or ACLs when required by your architecture.
  • Keep Redis updated.
  • Separate cache databases or key prefixes between sites.
  • Monitor memory usage.
  • Do not store sensitive application data in a cache without understanding its security requirements.

Best Redis Object Caching Practices for a Linux VPS

Use these practices when configuring Redis for WordPress:

  1. Keep Redis private. Use localhost or a private network whenever possible.
  2. Set a memory limit. Do not let a cache consume RAM needed by MySQL, PHP, and the operating system.
  3. Choose an eviction policy intentionally. A cache can usually regenerate evicted data, but application data may have different requirements.
  4. Use separate namespaces. Give each WordPress site a unique key prefix or Redis database where appropriate.
  5. Monitor before tuning. Check memory, hits, misses, and evictions before changing settings.
  6. Do not confuse page cache with object cache. LiteSpeed page caching and Redis solve different performance problems.
  7. Verify the PHP Redis extension. The extension must be available to the PHP version serving the website.
  8. Keep the object cache drop-in healthy. WordPress needs the persistent cache integration to actually use Redis.
  9. Do not blindly flush Redis. A shared Redis instance may contain data belonging to other applications or sites.
  10. Benchmark after changes. Compare TTFB, database activity, PHP execution time, and real user performance before and after configuration.

Redis Object Cache vs Memcached for WordPress

Both Redis and Memcached can provide persistent object caching for WordPress.

FeatureRedisMemcached
In-memory cachingYesYes
WordPress object cachingYesYes
Persistent object cacheYesYes
Data structuresRich data structuresSimpler key-value cache
Memory evictionMultiple policiesSupported
WordPress supportStrongStrong
Useful with LiteSpeedYesYes
Good choice for WordPress VPSYesYes

The right choice depends on your application, hosting stack, existing tooling, and operational requirements.

If your VPS already uses Redis and your WordPress stack supports it, there is usually no reason to introduce another caching service solely for object caching.

Does Redis Object Cache Reduce TTFB?

It can.

TTFB depends on everything between the client and the first byte of the response, including network latency, web server processing, PHP execution, database queries, application logic, and caching.

Redis can reduce the time WordPress spends retrieving repeatedly requested data from the database.

However, it does not guarantee a specific TTFB improvement.

For example:

Without object cache:

  Request

  PHP

  MySQL query

  Process result

  Response

With Redis:

Request

PHP

Redis lookup

Cached result

Response

The second path can be cheaper when the required data is already cached.

For the largest TTFB improvement, evaluate the complete stack instead of treating Redis as a standalone speed switch.

When Should You Use Redis Object Caching?

Redis object caching is particularly useful when:

  • WordPress performs many repeated database queries.
  • The site has logged-in users.
  • WooCommerce generates highly dynamic requests on cart and checkout pages that cannot utilize standard full-page caching. Activating an object cache layer is one of the most effective methods to speed up a WooCommerce store under high operational workloads.
  • Plugins rely heavily on database reads.
  • The site has a large or frequently accessed database.
  • The VPS has enough RAM for Redis.
  • Full page caching cannot cover every request.
  • WordPress Site Health recommends a persistent object cache.

It may provide less visible benefit on a small, mostly static site that is already fully served from a page cache.

The best way to determine whether Redis helps is to measure the workload before and after enabling it.

FAQs

Is Redis object caching safe to clear?

Usually, if Redis contains only disposable WordPress cache data, clearing the cache causes WordPress to regenerate the missing objects. However, never assume this is safe on a Redis server shared with other applications.

Does Redis replace MySQL in WordPress?

No. Redis acts as a cache layer. WordPress still relies on its database for persistent site data.

Does enabling Redis automatically improve every WordPress page?

No. Redis is most useful for dynamic application requests that actually access cached objects. A page already served directly from LiteSpeed’s full page cache may not need Redis at all.

What happens when Redis reaches its memory limit?

Redis follows the configured maxmemory-policy. Depending on the policy, it can evict keys or reject writes when the limit is reached.

Can Redis make a slow database query disappear?

No. Redis can avoid repeating a database operation when the required result is available in the object cache. A query that is never cached still reaches the database.

Final Takeaway

A Redis object cache adds a fast persistent caching layer between WordPress and its database. On a Linux VPS, the setup involves installing Redis, verifying the service, making the Redis client available to PHP, enabling the WordPress object cache drop-in, and monitoring memory and cache activity.

For a LiteSpeed WordPress stack, Redis works alongside full page caching rather than replacing it. LiteSpeed can handle complete cached pages while Redis helps WordPress retrieve frequently used objects when PHP still needs to run.

Start with a simple local Redis configuration, set a sensible memory limit, keep Redis private, monitor cache behavior, and measure your site’s TTFB before and after the change.

Ready to optimize your WordPress VPS? Install Redis, verify the connection with redis-cli ping, enable the WordPress object cache, and measure your TTFB and database workload before tuning further.

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat on WhatsApp