Examples: bulk update.

This commit is contained in:
Daniele Alessandri
2010-05-22 14:48:37 +02:00
parent d585b11bf5
commit dad3704488
6 changed files with 29 additions and 19 deletions
+3 -3
View File
@@ -1,10 +1,10 @@
<?php
require_once 'SharedConfigurations.php';
// when you have a whole set of consecutive commands to send to
// When you have a whole set of consecutive commands to send to
// a redis server, you can use a pipeline to improve performances.
$redis = Predis\Client::create($configurations);
$redis = new Predis\Client($single_server);
$replies = $redis->pipeline(function($pipe) {
$pipe->ping();
@@ -35,4 +35,4 @@ Array
)
*/
?>
?>
+3 -8
View File
@@ -1,5 +1,5 @@
<?php
require '../lib/Predis.php';
require_once 'SharedConfigurations.php';
// Developers can customize the distribution strategy used by the client
// to distribute keys among a cluster of servers simply by creating a class
@@ -40,16 +40,11 @@ class NaiveDistributionStrategy
}
}
$servers = array(
'redis://127.0.0.1:6379?alias=first',
'redis://127.0.0.1:6380?alias=second',
);
$options = array(
'key_distribution' => new NaiveDistributionStrategy(),
);
$redis = new Predis\Client($servers, $options);
$redis = new Predis\Client($multiple_servers, $options);
for ($i = 0; $i < 100; $i++) {
$redis->set("key:$i", str_pad($i, 4, '0', 0));
@@ -60,6 +55,6 @@ $server1 = $redis->getClientFor('first')->info();
$server2 = $redis->getClientFor('second')->info();
printf("Server '%s' has %d keys while server '%s' has %d keys.\n",
'first', $server1['db0']['keys'], 'second', $server2['db0']['keys']
'first', $server1['db15']['keys'], 'second', $server2['db15']['keys']
);
?>
+2 -2
View File
@@ -11,7 +11,7 @@ $mkv = array(
'usr:0003' => 'Third user'
);
$redis = Predis\Client::create($configurations);
$redis = new Predis\Client($single_server);
$redis->mset($mkv);
$retval = $redis->mget(array_keys($mkv));
@@ -26,4 +26,4 @@ Array
[2] => Third user
)
*/
?>
?>
+2 -2
View File
@@ -1,11 +1,11 @@
<?php
require_once '../lib/Predis.php';
require_once 'SharedConfigurations.php';
// Redis 2.0 features new commands that allow clients to subscribe for
// events published on certain channels (PUBSUB).
// Create a client and disable r/w timeout on the socket
$redis = new Predis\Client('redis://127.0.0.1:6379/?read_write_timeout=-1', 'dev');
$redis = new Predis\Client($single_server + array('read_write_timeout' => -1));
// Initialize a new pubsub context
$pubsub = $redis->pubSubContext();
+17 -2
View File
@@ -1,9 +1,24 @@
<?php
require_once '../lib/Predis.php';
$configurations = array(
$single_server = array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 15
);
?>
$multiple_servers = array(
array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 15,
'alias' => 'first',
),
array(
'host' => '127.0.0.1',
'port' => 6380,
'database' => 15,
'alias' => 'second',
),
);
?>
+2 -2
View File
@@ -3,7 +3,7 @@ require_once 'SharedConfigurations.php';
// simple set and get scenario
$redis = Predis\Client::create($configurations);
$redis = new Predis\Client($single_server);
$redis->set('library', 'predis');
$retval = $redis->get('library');
@@ -13,4 +13,4 @@ print_r($retval);
/* OUTPUT
predis
*/
?>
?>