Follow me on twitter…

Working with keys

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

In Redis we have 5 types of keys:



// Initialize Rediska
$options = array(
     'servers' => array(
         'server1' => array('host' => '', 'port' => 6379)
$rediska = new Rediska($options);

// Initialize key with name 'keyName'
$key = new Rediska_Key('keyName');

// Initialize key on server 'server1'
require_once 'Rediska/Key.php';
$key = new Rediska_Key('keyName', array(
    'serverAlias' => 'server1'

// Set value

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

// Initialize Set with name 'setKeyName' and specified Rediska instance
$set = new Rediska_Key_Set('setKeyName', array('rediska' => $rediska));

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


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

Available key options:

  • serverAlias - Server alias or Rediska_Connection object where key is placed. Если не указан то сервер выбирается автоматически с помошью key distributor
  • rediska - Rediska instance name, Rediska object or Rediska options for new instance. Default instance if not specified.


Fork me on GitHub