redis-cache icon indicating copy to clipboard operation
redis-cache copied to clipboard

Gracefully fail when Redis commands fail

Open danielvonmitschke opened this issue 1 year ago • 5 comments

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

danielvonmitschke avatar Apr 26 '23 11:04 danielvonmitschke

@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.

tillkruss avatar Apr 26 '23 16:04 tillkruss

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.

danielvonmitschke avatar Apr 26 '23 18:04 danielvonmitschke

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

tillkruss avatar Apr 26 '23 19:04 tillkruss

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.

waqasy avatar Sep 29 '23 19:09 waqasy

What an ignorant comment...

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

  • Why is WP_REDIS_GRACEFUL not enabled by default?
  • Is there a downside to using WP_REDIS_GRACEFUL?

You get excellent answers like:

  • WP_REDIS_GRACEFUL is not enabled by default, because the typical WordPress user does NOT monitor Redis, so they don't know whether Redis Server is available and object caching is working.
  • Using WP_REDIS_GRACEFUL is very risky, because if requests happen without the cache being updated (for example a checkout, or post is updated) then the SQL database will contain different information that what cache will return once the Redis Server is back online. This has lead to horrible dataloss (if you search the wp.org) forums.

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...

tillkruss avatar Sep 29 '23 22:09 tillkruss