Data encoding
Using Object Cache Pro’s serializer
and compression
configuration options reduces Redis memory usage by 70-80% and greatly reduces network communication.
While that’s fantastic, setting up, enabling and changing serialization and compression requires some extra steps.
Requirements
To use the igbinary
serializer, PHP must run the igbinary PHP extension and PhpRedis must be compiled with the --enable-redis-igbinary
flag.
Using any of the compressions requires PhpRedis to be compiled with their correlated flags, such as --enable-redis-zstd
and --enable-redis-lz4
.
Changing serializer/compression
Every time the serializer
or compression
configuration option is changed, you must flush your entire Redis database to avoid corrupt data and crashing your site.
If you can afford downtime in your development or staging environment, just go ahead and change serializer
/ compression
option and run redis-cli flushdb
.
In production environments that cannot afford downtime it’s recommended to:
- Disable the object cache:
wp redis disable
- Run
wp redis cli
and thenflushdb
- Change
serializer
/compression
option - Re-enable the object cache:
wp redis enable
Choosing a compression algorithm
The zstd
algorithm compresses data the smallest, lz4
compresses data the fastest and lzf
should only be used when the others aren’t available.