mirror of
https://github.com/predis/predis.git
synced 2026-09-16 13:27:14 +00:00
Examples: bulk update.
This commit is contained in:
@@ -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
|
||||
|
||||
)
|
||||
*/
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -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']
|
||||
);
|
||||
?>
|
||||
|
||||
@@ -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
|
||||
)
|
||||
*/
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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',
|
||||
),
|
||||
);
|
||||
?>
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user