Jelajahi Sumber

Rework examples for plain Redis commands.

Daniele Alessandri 11 tahun lalu
induk
melakukan
a00ffbf53f

+ 0 - 37
examples/MultipleSetAndGet.php

@@ -1,37 +0,0 @@
-<?php
-
-/*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-require 'SharedConfigurations.php';
-
-// redis can set keys and their relative values in one go
-// using MSET, then the same values can be retrieved with
-// a single command using MGET.
-
-$mkv = array(
-    'usr:0001' => 'First user',
-    'usr:0002' => 'Second user',
-    'usr:0003' => 'Third user'
-);
-
-$client = new Predis\Client($single_server);
-
-$client->mset($mkv);
-$retval = $client->mget(array_keys($mkv));
-
-var_export($retval);
-
-/* OUTPUT:
-array (
-  0 => 'First user',
-  1 => 'Second user',
-  2 => 'Third user',
-)
-*/

+ 55 - 0
examples/SendingRedisCommands.php

@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+require 'SharedConfigurations.php';
+
+$client = new Predis\Client($single_server);
+
+// Plain old SET and GET example...
+$client->set('library', 'predis');
+$response = $client->get('library');
+
+var_export($response); echo PHP_EOL;
+/* OUTPUT: 'predis' */
+
+// Redis has the MSET and MGET commands to set or get multiple keys in one go,
+// cases like this Predis accepts arguments for variadic commands both as a list
+// of arguments or an array containing all of the keys and/or values.
+$mkv = array(
+    'uid:0001' => '1st user',
+    'uid:0002' => '2nd user',
+    'uid:0003' => '3rd user'
+);
+
+$client->mset($mkv);
+$response = $client->mget(array_keys($mkv));
+
+var_export($response); echo PHP_EOL;
+/* OUTPUT:
+array (
+  0 => '1st user',
+  1 => '2nd user',
+  2 => '3rd user',
+) */
+
+// Predis can also send "raw" commands to Redis. The difference between sending
+// commands to Redis the usual way and the "raw" way is that in the latter case
+// their arguments are not filtered nor responses coming from Redis are parsed.
+
+$response = $client->raw(array('MGET', 'uid:0001', 'uid:0002', 'uid:0003'));
+
+var_export($response); echo PHP_EOL;
+/* OUTPUT:
+array (
+  0 => '1st user',
+  1 => '2nd user',
+  2 => '3rd user',
+) */

+ 0 - 25
examples/SimpleSetAndGet.php

@@ -1,25 +0,0 @@
-<?php
-
-/*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-require 'SharedConfigurations.php';
-
-// simple set and get scenario
-
-$client = new Predis\Client($single_server);
-
-$client->set('library', 'predis');
-$retval = $client->get('library');
-
-var_export($retval);
-
-/* OUTPUT
-'predis'
-*/