Rediska

Follow me on twitter…

Specify server for command

When you initialize Rediska to work with several redis servers it chooses server depending on key name.

In practice there may be situations when you want to specify server explicitly. With Rediska it can be done with proxying on($alias) method:

<?php

// Initialize Rediska with 3 servers
$options = array(
    'servers' => array(
        'exampleAlias' => array('host' => '127.0.0.1', 'port' => 6379),
        array('host' => '127.0.0.2', 'port' => 6379, 'alias' => 'exampleAlias2'),
        array('host' => '127.0.0.3', 'port' => 6379)
    )
);
$rediska = new Rediska($options);

// Set to specified server by alias
$rediska->on('exampleAlias')->set('a', 'b');

// Specified server for pipelines
$rediska->on('exampleAlias')
        ->pipeline()
        // Set to exampleAlias
        ->set('key1', 'value')
        // Set to exampleAlias
        ->set('key2', 'value')
        // Get from exampleAlias
        ->get('key1') 
        // Set to exampleAlias2
        ->on('exampleAlias2')->set('key3', 'value')
        // Get from exampleAlias
        ->get('key2', 'value')
        ->execute();

// If alias is not specified in server options you need to use default [host]:[port]
$rediska->on('127.0.0.3:6379')->set('key4', 'value');

?>

Comments

Fork me on GitHub