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

Redis cache, expired keys are not removed

Hello.

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:

$cache->exists($key);

returns TRUE. and

$cache->get($key)

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://127.0.0.1:6379?weight=1",
        'name' => SITE_DOMAIN . '-'
    ));

    $session->start();

    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:

$this->session->destroy();

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.

Redis

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



92

Hello

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



9.7k

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).