Home Ask Login Register

Developers Planet

Your answer is one click away!

Haz Pro February 2016

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 ?


Eli February 2016

Just use EXPIRE through predis:

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

kiss-web February 2016

You can do it in one command:

$client = new Predis\Client();
$client->set($key, $value, 'ex', 60);

But for maximum performance you should use phpredis extension, not predis library.

Post Status

Asked in February 2016
Viewed 2,607 times
Voted 4
Answered 2 times


Leave an answer

Quote of the day: live life