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:


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

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

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

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



Fork me on GitHub