[11.x] Fix Cache component to be aware of phpredis serialization and compression settings #54221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix Cache component to be aware of phpredis's serialization and compression settings.
--No breaking changes-- as the Cache component never worked properly with those settings enabled. If those settings are disabled, code path is the same as before.
Detailed Description
Three years ago, support for phpredis serialization and compression settings was added, working seamlessly with the Redis component. However, the Cache component is unaware of these settings and fails when they are set to anything other than
NONE
.Issues:
Double Serialization:
The Cache component serializes/unserializes data before sending it to Redis. When phpredis serialization is enabled, this results in redundant serialization, causing inefficiency. Solution: Skip Cache-level serialization if phpredis serialization is enabled.
EVAL Parameter Mismatch:
EVAL scripts require parameter values to be prepared client-side, which differs from the serialized/compressed values stored in Redis. Without proper preparation, scripts may fail. Solution: Use phpredis’s internal
pack
method to ensure EVAL parameters are consistent with stored values.Evidence
Screenshots demonstrate the issue when running existing tests using MSGPACK (serialization) and ZSTD (compression) enabled. Before the fix, the Cache component incorrectly php-serializes values, leaving them uncompressed and mismatched with stored values. After the fix, the EVAL parameters are smaller, correctly compressed, and match Redis-stored values.