We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Redis cache, expired keys are not removed


When i use the Phalcon\Cache\Backend\Redis cache it sets TTL to inserted keys. All looks good. But when TTL period ends, the key is not removed. The key still located in Redis.

And the worst thing:


returns TRUE. and


returns key, which TTL is ended.

"TTL %keyname%" returns -1, as expected. "GET %keyname%" returns key (Maybe it because TTL is not the same as EXPIRE, so key not deleted).

What i can do to force Phalcon (or Redis) automatically delete, or ignore, expired keys?

(Phalcon 2.0, Redis 2.8.19, Windows)

Can you provide example usage of when you set the key/value?

Also, which PHP client for redis are you using?

This is an example:

    $di->setShared('session', function() {
    $session = new Phalcon\Session\Adapter\Redis(array(
        'path' => "tcp://",
        'name' => SITE_DOMAIN . '-'


    return $session;

on Controller..

  $this->session->set(self::BTS_SESSION_USER_ID, 1); 
   $this->session->set(self::BTS_SESSION_USER_NAME, 'hugo');

But when i do:


The session persist! and not clean!

edited Nov '15

I can confirm this, in the following image, despite the keys test and online_1001 expired, it still continues to appear in PHCR set.


Link to image: https://prntscr.com/9155e2



I can see the same and after a while the memory is full. Did anyone find any solution?


The File backend has no file deletion that I can find. Lifetime only limits the files retrieved by get. It looks like you have to use QueryKeys to find old files then delete by key using ->delete($key).