Documents
- Get started!
- Configuration
-
Usage
- Working with keys
- Rediska API
- Pipelining
- Specify server for command
- Extending Rediska
- Integration with frameworks
- Examples
- Tests
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 require_once 'Rediska.php'; $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('key1', 'value') // on exampleAlias ->set('key2', 'value') // on exampleAlias ->get('key1') // on exampleAlias ->on('exampleAlias2')->set('key3', 'value') // on exampleAlias2 ->get('key2', 'value') // on exampleAlias ->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'); ?>