Skip to content

fix(cache): round-trip integer values in Redis adapter (#78)#79

Merged
ksandell merged 2 commits into
developfrom
fix/redis-int-roundtrip
May 21, 2026
Merged

fix(cache): round-trip integer values in Redis adapter (#78)#79
ksandell merged 2 commits into
developfrom
fix/redis-int-roundtrip

Conversation

@ksandell

Copy link
Copy Markdown
Contributor

Summary

Fixes #78 — the Redis cache adapter corrupted every integer value on read.

  • predis/predis GET always returns strings, so the is_int($result) fast-path in get() never matched and raw integers were passed to unserialize()false. Net effect: every integer stored via set() was irrecoverably corrupted to false on read.
  • get() now detects raw integers via filter_var($result, FILTER_VALIDATE_INT) — covering both set() of an int and native inc()/dec() counters.
  • Missing keys are now detected via an explicit === null check 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) because inc()/dec() rely on Redis native INCRBY/DECRBY, which require raw integer values.

Tests

  • Added testValueRoundTrip data-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.
  • Decode logic verified directly (Redis/APCu unavailable in local env → those suites skip).

Release

Bumps version 0.0.40 → 0.0.41 (VERSION, composer.json, package.json, CHANGELOG.md).

Test plan

  • CI: full PHPUnit suite passes
  • CI: Redis adapter testValueRoundTrip passes against the CI Redis service
  • CI: APCu adapter testValueRoundTrip passes

ksandell added 2 commits May 21, 2026 09:21
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.
@ksandell ksandell merged commit 1642f64 into develop May 21, 2026
4 checks passed
@ksandell ksandell deleted the fix/redis-int-roundtrip branch May 21, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis cache adapter corrupts integer values on round-trip (get returns false)

1 participant