An object cache keeps the results of repeated database queries in memory so WordPress does less work per page. Redis is a fast, widely used backend for it. This guide sets Redis up safely on a single server.
What does a Redis object cache do for WordPress? #
It stores query results and computed values in RAM, so repeat requests skip the database. Logged-in pages, admin screens, and dynamic content benefit most because full-page caches cannot serve them. Expect fewer database queries and lower response times on busy sites.
Step 1: Install and secure Redis #
sudo apt install -y redis-server
sudo nano /etc/redis/redis.conf
# /etc/redis/redis.conf
bind 127.0.0.1 -::1
protected-mode yes
maxmemory 256mb
maxmemory-policy allkeys-lru
supervised systemd
Step 2: Restart and test #
sudo systemctl restart redis-server
redis-cli ping # expect: PONG
Step 3: Connect WordPress #
Add the connection constants to wp-config.php above the line that says to stop editing, then enable your object-cache plugin.
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_CACHE_KEY_SALT', 'example.com:' );
Check that it is working #
- Load a few pages while logged out and logged in.
- Run
redis-cli info statsand comparekeyspace_hitswithkeyspace_misses. - A healthy site shows hits far above misses after the cache warms up.