We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Expired keys still exist in redis

I would like to inform a bug in redis cache implementation. The keys are not removed after its expiry.

Redis

In the screenshot, the keys test_ and online_1001 continues to exist in PHCR set even after expiry. Please note these keys are not present on the list on left panel.

Its problematic since

$cache->queryKeys();

would show even dead keys

Though when I try

$this->cache->exists('test_');

it returns correctly (i.e.,false)

This 'feature' is not specific only to Redis. All backend adapters implemented in Phalcon work like that. queryKeys() method will always return all keys ever stored. That's due to the existence of 'statsKey' bag being set not to expire by default. If you ommit key during cache initialization, queryKeys() method will not work. But you resolve this issue. Define it like this for backend cache adapters:

            'lifetime' => 0x0000000a,
            'prefix'   => 'cartData_', //actual prefix of the keys
            'statsKey' => null