Rediska

Follow me on twitter…

Working with keys

One of the great features is working with keys as with objects.

In Redis we have 4 types of keys:

Example

<?php

// Initialize key with name "keyName"
require_once 'Rediska/Key.php';
$key = new Rediska_Key('keyName');

// Initialize key with 5 minutes expiration time on server with alias 'server1'
require_once 'Rediska/Key.php';
$key = new Rediska_Key('keyName', 60 * 5, 'server1');

// Set value
$key->setValue('value');

// Print value
print $key; #=> value

// Initialize Set with name "setKeyName"
require_once 'Rediska/Key/Set.php';
$set = new Rediska_Key_Set('setKeyName');

// Print all elements
foreach($set as $element) {
    print $element;
}

?>

As you see, working with key objects is easy and fun.

Key objects use default Rediska instance or (if it's not set) initialize it with default options. You can set an instance explicitly using setRediska(Rediska $rediska) method.

Comments