|
@@ -0,0 +1,81 @@
|
|
|
+<?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';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+use Predis\Profiles\ServerProfile;
|
|
|
+use Predis\Commands\ScriptedCommand;
|
|
|
+use Predis\Network\MasterSlaveReplication;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class HashMultipleGetAll extends ScriptedCommand {
|
|
|
+ const BODY = <<<EOS
|
|
|
+local hashes = {}
|
|
|
+for _, key in pairs(KEYS) do
|
|
|
+ table.insert(hashes, key)
|
|
|
+ table.insert(hashes, redis.call('hgetall', key))
|
|
|
+end
|
|
|
+return hashes
|
|
|
+EOS;
|
|
|
+
|
|
|
+ public function getScript() {
|
|
|
+ return self::BODY;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+$parameters = array(
|
|
|
+ 'tcp://127.0.0.1:6379/?alias=master',
|
|
|
+ 'tcp://127.0.0.1:6380/?alias=slave',
|
|
|
+);
|
|
|
+
|
|
|
+$options = array(
|
|
|
+ 'profile' => function($options) {
|
|
|
+ $profile = ServerProfile::get('dev');
|
|
|
+ $profile->defineCommand('hmgetall', 'HashMultipleGetAll');
|
|
|
+
|
|
|
+ return $profile;
|
|
|
+ },
|
|
|
+ 'replication' => function($options) {
|
|
|
+ $replication = new MasterSlaveReplication();
|
|
|
+ $replication->setScriptReadOnly(HashMultipleGetAll::BODY);
|
|
|
+
|
|
|
+ return $replication;
|
|
|
+ },
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+$client = new Predis\Client($parameters, $options);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+$hashes = $client->hmgetall('metavars', 'servers');
|
|
|
+
|
|
|
+$replication = $client->getConnection();
|
|
|
+$stillOnSlave = $replication->getCurrent() === $replication->getConnectionById('slave');
|
|
|
+
|
|
|
+echo "Is still on slave? ", $stillOnSlave ? 'YES' : 'NO', "!\n";
|
|
|
+var_export($hashes);
|