Browse Source

Apply minor changes to the rest of the examples.

Daniele Alessandri 13 years ago
parent
commit
2f23fb03f0

+ 7 - 6
examples/CustomDistributionStrategy.php

@@ -62,19 +62,20 @@ class NaiveDistributionStrategy implements IDistributionStrategy
 
 $options = array(
     'cluster' => function() {
-        return new PredisCluster(new NaiveDistributionStrategy());
+        $distributor = new NaiveDistributionStrategy();
+        return new PredisCluster($distributor);
     },
 );
 
-$redis = new Predis\Client($multiple_servers, $options);
+$client = new Predis\Client($multiple_servers, $options);
 
 for ($i = 0; $i < 100; $i++) {
-    $redis->set("key:$i", str_pad($i, 4, '0', 0));
-    $redis->get("key:$i");
+    $client->set("key:$i", str_pad($i, 4, '0', 0));
+    $client->get("key:$i");
 }
 
-$server1 = $redis->getClientFor('first')->info();
-$server2 = $redis->getClientFor('second')->info();
+$server1 = $client->getClientFor('first')->info();
+$server2 = $client->getClientFor('second')->info();
 
 printf("Server '%s' has %d keys while server '%s' has %d keys.\n",
     'first', $server1['db15']['keys'], 'second', $server2['db15']['keys']

+ 4 - 4
examples/MultiExecTransactionsWithCAS.php

@@ -26,7 +26,6 @@ require 'SharedConfigurations.php';
 function zpop($client, $key)
 {
     $element = null;
-
     $options = array(
         'cas'   => true,    // Initialize with support for CAS operations
         'watch' => $key,    // Key that needs to be WATCHed to detect changes
@@ -34,7 +33,7 @@ function zpop($client, $key)
                             // which the client bails out with an exception.
     );
 
-    $txReply = $client->multiExec($options, function($tx) use ($key, &$element) {
+    $client->multiExec($options, function($tx) use ($key, &$element) {
         @list($element) = $tx->zrange($key, 0, 0);
 
         if (isset($element)) {
@@ -42,10 +41,11 @@ function zpop($client, $key)
             $tx->zrem($key, $element);
         }
     });
+
     return $element;
 }
 
-$redis = new Predis\Client($single_server);
-$zpopped = zpop($redis, 'zset');
+$client = new Predis\Client($single_server);
+$zpopped = zpop($client, 'zset');
 
 echo isset($zpopped) ? "ZPOPed $zpopped" : "Nothing to ZPOP!", "\n";

+ 3 - 3
examples/MultipleSetAndGet.php

@@ -21,10 +21,10 @@ $mkv = array(
     'usr:0003' => 'Third user'
 );
 
-$redis = new Predis\Client($single_server);
+$client = new Predis\Client($single_server);
 
-$redis->mset($mkv);
-$retval = $redis->mget(array_keys($mkv));
+$client->mset($mkv);
+$retval = $client->mget(array_keys($mkv));
 
 print_r($retval);
 

+ 2 - 2
examples/PipelineContext.php

@@ -14,9 +14,9 @@ require 'SharedConfigurations.php';
 // When you have a whole set of consecutive commands to send to
 // a redis server, you can use a pipeline to improve performances.
 
-$redis = new Predis\Client($single_server);
+$client = new Predis\Client($single_server);
 
-$replies = $redis->pipeline(function($pipe) {
+$replies = $client->pipeline(function($pipe) {
     $pipe->ping();
     $pipe->flushdb();
     $pipe->incrby('counter', 10);

+ 3 - 3
examples/PubSubContext.php

@@ -15,10 +15,10 @@ require 'SharedConfigurations.php';
 // events published on certain channels (PUBSUB).
 
 // Create a client and disable r/w timeout on the socket
-$redis  = new Predis\Client($single_server + array('read_write_timeout' => 0));
+$client = new Predis\Client($single_server + array('read_write_timeout' => 0));
 
 // Initialize a new pubsub context
-$pubsub = $redis->pubSub();
+$pubsub = $client->pubSub();
 
 // Subscribe to your channels
 $pubsub->subscribe('control_channel', 'notifications');
@@ -57,5 +57,5 @@ foreach ($pubsub as $message) {
 unset($pubsub);
 
 // Say goodbye :-)
-$info = $redis->info();
+$info = $client->info();
 print_r("Goodbye from Redis v{$info['redis_version']}!\n");

+ 5 - 5
examples/SimpleDebuggableConnection.php

@@ -67,12 +67,12 @@ $options = array(
     ),
 );
 
-$redis = new Predis\Client($single_server, $options);
-$redis->set('foo', 'bar');
-$redis->get('foo');
-$redis->info();
+$client = new Predis\Client($single_server, $options);
+$client->set('foo', 'bar');
+$client->get('foo');
+$client->info();
 
-print_r($redis->getConnection()->getDebugBuffer());
+print_r($client->getConnection()->getDebugBuffer());
 
 /* OUTPUT:
 Array

+ 3 - 3
examples/SimpleSetAndGet.php

@@ -13,10 +13,10 @@ require 'SharedConfigurations.php';
 
 // simple set and get scenario
 
-$redis = new Predis\Client($single_server);
+$client = new Predis\Client($single_server);
 
-$redis->set('library', 'predis');
-$retval = $redis->get('library');
+$client->set('library', 'predis');
+$retval = $client->get('library');
 
 var_dump($retval);