Follow me on twitter…


Good news, you can work with Redis lists as with native PHP arrays:


// Initialize Rediska
$rediska = new Rediska();

// Initialize list
$list = new Rediska_Key_List('list');

// Add two elements to list
$list[] = 'first element';
$list[] = 'second element';

// Get element with index 1
echo $list[1]; #=> 'second element';

// Set element with index 0
$list[0] = 'new first element';

// Get elements count
echo count($list); #=> 2

// Check if element with index 0 is present
echo isset($list[0]); #=> true

// Iterate list
foreach($list as $element) {
    echo $element;


See all available methods.


Carlo July 05, 2012 10:38

I am having difficulties on trying to set the expire time in seconds for a particular List key. I am using a list to insert last viewed items for a particular username. Evey time I insert a new item into the list I'd like to refresh the expiring time to 24 hour. What I do in php is:

but I have also tried:

Well every time I set the expiring time in that way the list get reset and looks empty.
If I remove that line list keeps getting populated. I can set expire just when I add the first item, in that case it works but I'd like to make the key expire if a user hasn't viewed any item for 24 hour.

Any suggestions?

Yegor November 27, 2012 20:51


I used public method truncate for clear elements from list. I tried:

$list = new Rediska_Key_List('list');
$list->truncate(1, -1); // returned true constantly

In method-realisation I found if-container:

if (!is_null($this->getExpire()) && $result) {

Why is this expire-method?

In comments nothing about expire!

Fork me on GitHub