Skip to content

Commit 788d346

Browse files
committed
fix: incorrect metadata querying of Redis cache
1 parent 4aa93c5 commit 788d346

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

system/Cache/Handlers/RedisHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,11 @@ public function getCacheInfo()
233233
*/
234234
public function getMetaData(string $key)
235235
{
236-
$key = static::validateKey($key, $this->prefix);
237236
$value = $this->get($key);
238237

239238
if ($value !== null) {
240239
$time = Time::now()->getTimestamp();
241-
$ttl = $this->redis->ttl($key);
240+
$ttl = $this->redis->ttl(static::validateKey($key, $this->prefix));
242241

243242
return [
244243
'expire' => $ttl > 0 ? $time + $ttl : null,

tests/system/Cache/Handlers/AbstractHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
abstract class AbstractHandlerTest extends CIUnitTestCase
2121
{
22-
protected $handler;
22+
protected BaseHandler $handler;
2323
protected static $key1 = 'key1';
2424
protected static $key2 = 'key2';
2525
protected static $key3 = 'key3';

tests/system/Cache/Handlers/RedisHandlerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ public function testGetCacheInfo()
198198
$this->assertIsArray($this->handler->getCacheInfo());
199199
}
200200

201+
public function testGetMetadataNotNull(): void
202+
{
203+
$this->handler->save(self::$key1, 'value');
204+
205+
$metadata = $this->handler->getMetaData(self::$key1);
206+
207+
$this->assertNotNull($metadata);
208+
$this->assertIsArray($metadata);
209+
}
210+
201211
public function testIsSupported()
202212
{
203213
$this->assertTrue($this->handler->isSupported());

0 commit comments

Comments
 (0)