Maintenance

"Error Establishing a Redis Connection" in WordPress: What It Means and How to Fix It

Fix "Error establishing a Redis connection" in WordPress: Redis stopped, wrong host or port after a migration, a leftover object-cache.php or memory.

On this page
  1. Get the site back online first
  2. Find and fix the cause
  3. The error appears only some of the time
  4. After a migration or a host change
  5. Edge cases
  6. FAQs
Key takeaways
  • The error means object-cache.php tells WordPress to use Redis but Redis can't be reached; renaming that file brings the site back without losing data.
  • Common causes are Redis stopped, the wrong host, port or socket in wp-config.php after a migration, or a drop-in left on a host without Redis.
  • Check redis-cli ping, the connection constants, memory and the Redis log, then re-enable the object cache.

"Error establishing a Redis connection" means WordPress has an object cache drop-in (wp-content/object-cache.php) that tells it to use Redis, but it cannot reach the Redis server, usually because Redis has stopped, the host or port in wp-config.php is wrong after a migration, or the drop-in was left behind on a server without Redis.

Your posts and orders are safe. Redis only stores temporary copies of database results, so the quickest way to get the site back is to remove the drop-in; then fix Redis and switch caching back on.

Get the site back online first

  1. Open File Manager or SFTP and go to /wp-content/.
  2. Rename object-cache.php to object-cache.php.off. WordPress now ignores Redis and reads straight from the database.
  3. Load the site. It should work, a little slower than before. If it still fails, the error is something else; check error establishing a database connection, which is a different message about MySQL.

Find and fix the cause

  1. Check Redis is running. On a VPS, run redis-cli ping. A reply of PONG means Redis is up. No reply means start it with sudo systemctl start redis-server (the service may be named redis on some systems) and enable it at boot with sudo systemctl enable redis-server. On shared or managed hosting, check that Redis or "object cache" is still switched on in the panel, for example hPanel > Advanced or the host's caching page.
  2. Check the connection settings. Open wp-config.php and look for lines like WP_REDIS_HOST, WP_REDIS_PORT, WP_REDIS_PATH (for a Unix socket) and WP_REDIS_PASSWORD. After a move to new hosting these often still point at the old server. The usual local values are host 127.0.0.1 and port 6379, but many hosts use a socket path or a custom port, so copy the exact values from the host's Redis page.
  3. Check the database number and prefix if several sites share one Redis server. Two sites using the same database index and no prefix will overwrite each other's cache. Set a unique WP_REDIS_PREFIX (or WP_CACHE_KEY_SALT) for each site.
  4. Check Redis memory. If Redis is full and has no eviction policy, writes fail. Run redis-cli info memory and look at used_memory_human against maxmemory. Setting maxmemory-policy allkeys-lru in the Redis config lets old keys drop out instead of failing.
  5. Read the Redis log for crashes or out-of-memory kills, usually at /var/log/redis/redis-server.log on Ubuntu.
  6. Turn the cache back on. Rename object-cache.php.off back, or in the Redis Object Cache plugin go to Settings > Redis and click Enable Object Cache. The status should say "Connected".

The error appears only some of the time

Intermittent Redis errors usually mean Redis is restarting, running out of memory, or taking too long to answer under load. Add a short timeout to wp-config.php, for example define( 'WP_REDIS_TIMEOUT', 1 ); and define( 'WP_REDIS_READ_TIMEOUT', 1 );, then check memory and the log as above. If it happens during backups, the server may be short of RAM for both jobs at once.

After a migration or a host change

This is the most common time to see the error. A backup or migration plugin copies object-cache.php along with everything else, but the new host may not have Redis at all, or has it on a different socket.

  • If the new host has no Redis, delete object-cache.php and remove the Redis plugin, or switch to the host's own object cache if it has one.
  • If it does, update the host, port or socket path to the new values.
  • Add this check to your move plan; our WordPress migration service includes it for every move.

Edge cases

  • Two drop-ins fighting. LiteSpeed Cache, W3 Total Cache and the Redis Object Cache plugin can each write object-cache.php. Use object caching in one plugin only.
  • Plugin removed, drop-in kept. Deleting the plugin doesn't always delete the drop-in. If the error appears after you "removed Redis", delete the file by hand.
  • Docker setups. Inside a container 127.0.0.1 means the container itself. Use the Redis service name from your compose file as the host.

If you're adding Redis for speed, it helps logged-in users, WooCommerce and busy admin screens most; see WooCommerce speed optimisation for where it fits.

FAQs

Will I lose data if I delete object-cache.php?

No. Redis holds only cached copies. Everything real is in the MySQL database.

Do I need Redis for WordPress?

No. Small brochure sites do fine with page caching alone. Redis helps sites with many logged-in users, stores and heavy admin use.

Why does the admin show "Not connected" in the Redis plugin?

The plugin can't reach Redis with the settings in wp-config.php. Check that the service is running and that host, port, socket and password match what your host gives.

Need help with your website?

I'm a freelance WordPress developer building fast, SEO-friendly websites since 2020. Tell me what you need and I'll reply with a plan and a fixed quote, usually within 24 hours.

Found this useful? Share it:
Contact

Let's build your next website

Available for freelance projects, agency white-label work and long-term maintenance. Feel free to pass this along to your team or company.

I reply within 24 hours, usually the same day. Your details are emailed to me, then WhatsApp opens so we can chat right away.

Chat now