diff --git a/src/Cache/Adapter/Redis.php b/src/Cache/Adapter/Redis.php index 1df8d119d3..67dd8ee979 100644 --- a/src/Cache/Adapter/Redis.php +++ b/src/Cache/Adapter/Redis.php @@ -277,7 +277,8 @@ class Redis implements Adapter, Leasable, Retryable return []; } - return $keys; + // Don't expose the internal generation field as a listable cache field. + return \array_values(\array_filter($keys, fn (string $field): bool => $field !== self::GENERATION_FIELD)); } /** diff --git a/tests/Cache/E2E/Redis/LeasableTest.php b/tests/Cache/E2E/Redis/LeasableTest.php index e2ae7389a7..187c352131 100644 --- a/tests/Cache/E2E/Redis/LeasableTest.php +++ b/tests/Cache/E2E/Redis/LeasableTest.php @@ -113,4 +113,16 @@ class LeasableTest extends TestCase $this->assertSame('1', $this->cache->getGeneration('doc:1')); $this->assertFalse($this->cache->saveWithLease('doc:1', 'stale', 'doc:1', '0')); } + + public function testListHidesGenerationField(): void + { + $this->cache->flush(); + $this->cache->saveWithLease('doc:1', ['v' => 1], 'field-a', $this->cache->getGeneration('doc:1')); + $this->assertSame(['field-a'], $this->cache->list('doc:1')); + + // After a purge the key holds only its internal generation field, which + // must not surface as a listable cache field. + $this->cache->purge('doc:1'); + $this->assertSame([], $this->cache->list('doc:1')); + } }