fix(memcache): preserve float values in Redis-based cache backends#62104
Open
joshtrichards wants to merge 3 commits into
Open
fix(memcache): preserve float values in Redis-based cache backends#62104joshtrichards wants to merge 3 commits into
joshtrichards wants to merge 3 commits into
Conversation
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
susnux
reviewed
Jul 14, 2026
|
|
||
| protected static function decodeValue(string $value): mixed { | ||
| return is_numeric($value) ? (int)$value : json_decode($value, true); | ||
| return json_decode($value, true, 512, JSON_THROW_ON_ERROR); |
Contributor
There was a problem hiding this comment.
Suggested change
| return json_decode($value, true, 512, JSON_THROW_ON_ERROR); | |
| return json_decode($value, true, flags: JSON_THROW_ON_ERROR); |
susnux
reviewed
Jul 14, 2026
| */ | ||
| protected static function decodeValue(string $value): mixed { | ||
| return is_numeric($value) ? (int)$value : json_decode($value, true); | ||
| return json_decode($value, true, 512, JSON_THROW_ON_ERROR); |
Contributor
There was a problem hiding this comment.
Suggested change
| return json_decode($value, true, 512, JSON_THROW_ON_ERROR); | |
| return json_decode($value, true, flags: JSON_THROW_ON_ERROR); |
susnux
approved these changes
Jul 14, 2026
susnux
left a comment
Contributor
There was a problem hiding this comment.
Looks good but instead of using the default you can just use the named parameter so its a bit more clear why it is set (you not actually setting the depth but only the flags)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Preserve float values in Redis/Valkey-backed memcache backends.
This updates
RedisandKeyValueCacheto:json_decode(...)instead of coercing all numeric payloads tointJSON_PRESERVE_ZERO_FRACTIONso1.0stays distinct from1It also adds shared round-trip test coverage in
tests/lib/Memcache/Cache.php, including floats and numeric edge cases.Before / after
Before
3.14→31.0→1After
3.14→3.141.0→1.0Notes
This slightly changes the cache format for values like
1.0, so older entries may not compare equal in Redis-side CAS/Lua operations until they expire and are rewritten.Down the road we may want to consider using
_pack/_unpack(at least for phpredis; not sure about predis).TODO
KeyValueCacheTestonce deciding what to do about the embedded comments thereChecklist
3. to review, feature component)stable32)AI (if applicable)