Search code examples
phpcodeigniterredispredis

Setting cache timeout to a key in Codeigniter using predis package


In Codeigniter, I've installed predis package using Composer. I'm able to set and get the value from cache using this package. My requirement is I need to keep the value in cache using Redis for 1 min. I have seen different options setting through Redis Terminal. But I need to set the time limit in controller Itself. Any Idea ?


Solution

  • Just use EXPIRE through predis:

    $client = new Predis\Client();
    $client->set('foo', 'bar');
    $client->expire('foo', 60);