rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
428 stars 149 forks source link

Incorrect cache behavior with 2 servers using AWS load balancer #542

Closed allweek closed 1 month ago

allweek commented 1 month ago

Description

The website uses two servers with an AWS load balancer.

I open the website in two different browsers on the same PC, which typically connect to two different servers.

When I change something in wp-admin (e.g., page text) in the first browser, the update is only reflected in that browser.

Expected Behavior

Changes should be applied to both websites (on both servers).

Actual Behavior

The second browser shows an old version of the page (inside wp-admin and on website). Hard reload in Chrome doen't help. "Flush cache" in the second browser resolves the issue, but it is difficult to determine which browser is the second one, especially when multiple people are editing the website in wp-admin.

Additional context

When I change data in the first browser, a request must be made to the cache to update the data , but it doesn't happen. However, when I make a change in the second browser, the request is made, but it saves the incorrect data from the first change .

To fix this, I had to add the following in wp-config:

define( 'WP_REDIS_IGNORED_GROUPS', ['options', 'posts', 'plugins']);

This helps, but it is not optimal for caching.

Environment

The wp-config is the same on both servers, and WP_CACHE_KEY_SALT is also identical.

tillkruss commented 1 month ago

Are you using a single Redis Server, or does each node have it's own Redis instance?

allweek commented 1 month ago

Are you using a single Redis Server, or does each node have it's own Redis instance?

Single Redis server for both

allweek commented 1 month ago

Upd: update version from 2.5.0 to 2.5.3 doesn't help.

It seems that instead of updating the cache immediately after modifying the data, it saves the request in Redis and sends it later. Is it possible?

tillkruss commented 1 month ago

Single Redis server for both

You can't do that. You must use a single server, or Redis replication, just like you do with SQL.

allweek commented 1 month ago

Single Redis server for both

You can't do that. You must use a single server, or Redis replication, just like you do with SQL.

Sorry, maybe you misunderstood. We have two WordPress instances, and requests to them are routed via an AWS ALB. These servers are identical twins, and they use the same Redis server. Settings are the same in Redis Cache Plugin, including the WP_REDIS_PREFIX and WP_CACHE_KEY_SALT values (different values also don't work correctly).