fix(cache): round-trip integer values in Redis adapter (#78)#79
Merged
Conversation
Redis get() returned false for any integer stored via set() because Predis always returns strings, so the is_int() fast-path never matched and the raw integer was passed to unserialize(). get() now detects raw integers via filter_var() and uses an explicit null check so falsy stored values are no longer mistaken for cache misses. Adds testValueRoundTrip data-provider regression tests to the Redis and APCu adapter suites. Bumps version to 0.0.41.
The @dataProvider docblock annotation is not recognized under PHPUnit 12 (PHP 8.3/8.4 CI matrix), causing testValueRoundTrip to run with zero arguments and error. The PHP 8 attribute form works across all PHPUnit versions in the matrix.
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
Fixes #78 — the Redis cache adapter corrupted every integer value on read.
predis/predisGETalways returns strings, so theis_int($result)fast-path inget()never matched and raw integers were passed tounserialize()→false. Net effect: every integer stored viaset()was irrecoverably corrupted tofalseon read.get()now detects raw integers viafilter_var($result, FILTER_VALIDATE_INT)— covering bothset()of an int and nativeinc()/dec()counters.=== nullcheck instead of a truthy test, so falsy stored values (0,0.0,'',false,'0') are no longer mistaken for cache misses.set()retains raw-integer storage (rather than the issue's uniform-serialize()suggestion) becauseinc()/dec()rely on Redis nativeINCRBY/DECRBY, which require raw integer values.Tests
testValueRoundTripdata-provider regression tests to both the Redis and APCu adapter suites, covering ints, zero, negatives, floats, booleans, empty/numeric strings, null, and arrays — a reusable guard against type-corruption regressions in any adapter.Release
Bumps version 0.0.40 → 0.0.41 (
VERSION,composer.json,package.json,CHANGELOG.md).Test plan
testValueRoundTrippasses against the CI Redis servicetestValueRoundTrippasses