- Requirements
- Changing serializer/compression
- Choosing a compression algorithm
- Installation
- igbinary serializer
- lzf/lz4/zstd compression
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, the PHP installation must have the igbinary PHP extension installed and the PhpRedis extension must be compiled with the --enable-redis-igbinary
flag.
To use any of the compression algorithm requires PhpRedis to be compiled with their correlated flags, such as --enable-redis-zstd
and --enable-redis-lz4
.
Learn more about compiling PhpRedis.
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.
Installation
igbinary serializer
The easiest way to install igbinary
and enable PhpRedis support for it is using pecl
if it is available on the system:
pecl install igbinary
pecl install --configureoptions='enable-redis-igbinary="yes"' redis
If PECL isn’t available, igbinary can be compiled from source.
lzf/lz4/zstd compression
The easiest way to install any of the compression algorithms is using pecl
.
# Use prompts
pecl install redis
# Skip prompts
pecl install --configureoptions='enable-redis-lzf="yes" enable-redis-zstd="yes" enable-redis-lz4="yes"' redis
If PECL isn’t available, PhpRedis can be compiled from source.