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
427 stars 149 forks source link

Gracefully fail when Redis commands fail #461

Open danielvonmitschke opened 1 year ago

danielvonmitschke commented 1 year ago

Hi,

I am using redis-cache on a plesk server with a bitnami/redis docker container.

In my log file I get quite a few fatal errors in the form of Uncaught RedisException: read error on connection to 127.0.0.1:6379 in /var/www/vhosts/sites/www.web/app/object-cache.php:1897.

In your FAQ your write to just ignore there error and that would be total fine with me.

Unfortunately there is a "BUT": I saw quite a few instances where this caused some basic wordpress or woocommerce "operations" to fail. And in my opinion that should not be the case.

Here is what I mean with that: We have some operation in wordpress or woocommerce that is trying to "do" something and in some place it uses caching or transients. Most of the time that would be just asking if there is some value in the cache and if not to do a costly calculation of this value. But if there is a connection problem with redis this causes the whole operation to break. Instead redis-cache should fail gracefully in this case and just behave as if the value wasn't present in the cache (e.g. return false or whatever the default value is for that). This of course should be applied to all redis cache functions. This way we wouldn't break any higher level operations just because the cache is not working for a split second.

Please let me know what you think.

Best,

daniel

tillkruss commented 1 year ago

@danielvonmitschke: That's exactly what Object Cache Pro does. However this plugin would need quite a bit of work done to accomplish that. We're always open to a pull request if you like to contribute this.

danielvonmitschke commented 1 year ago

Thank you. Unfortunately the pro version is out of our price range. Actually never realized that the pro version is a plugin. It seemed more like an external caching service (though I wouldn't know how this would work non-local). at least the monthly fee suggested that this is not only a plugin.

tillkruss commented 1 year ago

Yeah, it's certainly a high end product. It looks like non of the FOSS plugins do graceful return values.

waqasy commented 11 months ago

My mind boggles to see that this plugin has option "WP_REDIS_GRACEFUL" parameter to bypass 500 error when redis not available, yet developer hasn't added this option in plugin settings by default. Why the sites of naive users should appear broken and face alot of panic when 500 error appear for visitors (which may last for hours when go unnoticed)

What OP has asked is very basic behavior of any reasonable caching plugin offers. Actually this is the prime feature of every cache solution. to use fallback if cache not available or service unavailable.

tillkruss commented 11 months ago

What an ignorant comment...

When the mind is boggled, it's wise to ask questions. For example:

You get excellent answers like:

Furthermore, if you'd like a better WP_REDIS_GRACEFUL support, this is free and open source software and you could open a Pull Request. Even if you can't code, you could extend the documentation and installation instruction instead of whining...