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

WP_REDIS_SERIALIZER vs WP_REDIS_IGBINARY #440

Closed nixsee closed 1 year ago

nixsee commented 1 year ago

I have Redis Object Cache installed on my WordPress site and have configured Relay on my server. It connects and works fine. In wp-config.php I have the following two lines:

define('WP_REDIS_SERIALIZER', Redis::SERIALIZER_IGBINARY);
define('WP_REDIS_IGBINARY', true);

And both are recognized in the diagnostics as 2 and true, respectively.

It isn't clear to me if I should be using one or the other, or both. When I step through the code with Xdebug, it seems like these two settings are in conflict/competition with each other. If WP_REDIS_SERIALIZER is set, it never seems to get to the point where it checks for/uses WP_REDIS_IGBINARY - for example, here https://github.com/rhubarbgroup/redis-cache/blob/develop/includes/object-cache.php#L2722

Also, in the Scaling section of the readme, it shows define( 'WP_REDIS_SERIALIZER', 'igbinary' );

but I was under the impression that you needed to set it as I did above (Redis::SERIALIZER_IGBINARY)

So, I'm hoping you could please clarify a bit further here or in the Readme what each one does, why you'd use one over the other, and how to set them. Again, I'm using Relay, but I suppose instructions for both Relay and phpredis would be useful (if there's a difference).

Thanks!

tillkruss commented 1 year ago

It looks like the WP_REDIS_SERIALIZER is used for PhpRedis and Relay and will set the Redis::OPT_SERIALIZER option.

And WP_REDIS_IGBINARY will use the igbinary_*() methods to compress data.

I think we should remove WP_REDIS_SERIALIZER, it's not safe anyhow to use the JSON or MSGPACK options.

nixsee commented 1 year ago

Thanks for the quick response!

But its still not quite clear to me, so please bear with me.

I'd like to use the most performant serializer available. I think that is igbinary, but it is not clear to me whether that is igbinary_*() or Relay\Relay::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY or Relay\Relay::OPT_SERIALIZER, 'igbinary.

Though, it sounds like you plan to remove WP_REDIS_SERIALIZER, so that just leaves define('WP_REDIS_IGBINARY', true);

If its helpful, I'm happy to submit an initial PR to remove WP_REDIS_SERIALIZER for your review.

tillkruss commented 1 year ago

Closed via 4bbcf34da35e60526727209bc5a9cc8235745f85.

nickchomey commented 1 year ago

I'm very sorry - I just got (made) time to come back and finish this issue/PR off, but see that you did it yourself today...

tillkruss commented 1 year ago

No worries!