/** * Magic method to handle all function requests and prefix key based * operations with the '{self::$defaultNamespace}' key prefix. * * @param string $name The name of the method called. * @param array $args Array of supplied arguments to the method. * @return mixed Return value from Resident::call() based on the command. */ public function __call($name, $args) { $args = func_get_args(); if (in_array($name, $this->keyCommands)) { $args[1][0] = self::$defaultNamespace . $args[1][0]; } try { return parent::__call($name, $args[1]); } catch (RedisException $e) { return false; } }
/** * Magic method to handle all function requests and prefix key based * operations with the 'resque:' key prefix. * * @param string $name The name of the method called. * @param array $args Array of supplied arguments to the method. * @return mixed Return value from Resident::call() based on the command. */ public function __call($name, $args) { $args = func_get_args(); if (in_array($name, $this->keyCommands)) { $args[1][0] = 'resque:' . $args[1][0]; } try { return parent::__call($name, $args[1]); } catch (RedisException_a $e) { return false; } }
<?php error_reporting(E_ALL); include '../redisent_cluster.php'; $cluster = new RedisentCluster(array('alpha' => array('host' => '127.0.0.1', 'port' => 6379), 'beta' => array('host' => '127.0.0.1', 'port' => 6380))); echo "Set 'pokemon' to 'squirtle' on alpha\n"; $cluster->to('alpha')->set('pokemon', 'squirtle'); echo "Set 'pokemon' to 'bulbasaur' on beta\n"; $cluster->to('beta')->set('pokemon', 'bulbasaur'); if ($cluster->to('alpha')->get('pokemon') == 'squirtle') { echo "[PASS] Got 'squirtle' from 'pokemon' on alpha, great!\n"; } else { echo "[FAIL] Seems we have a Poke-mixup on alpha\n"; } if ($cluster->to('beta')->get('pokemon') == 'bulbasaur') { echo "[PASS] Got 'bulbasaur' from 'pokemon' on beta, great!\n"; } else { echo "[FAIL] Seems we have a Poke-mixup on beta\n"; }
$lines = explode("\n", file_get_contents("keys.test")); foreach ($lines as $line) { $pair = explode(':', trim($line)); if (count($pair) >= 2) { $keys[$pair[0]] = $pair[1]; } } echo sprintf("Got %d keys\n", count($keys)); /* Use a cluster of 3 servers, make sure they're clean */ echo "Using a cluster of 3 servers\n"; $cluster = new RedisentCluster(array(array('host' => '127.0.0.1', 'port' => 6379), array('host' => '127.0.0.1', 'port' => 6380), array('host' => '127.0.0.1', 'port' => 6381))); echo sprintf("Setting %d keys\n", count($keys)); foreach ($keys as $key => $value) { $cluster->set($key, $value); } /* Now use a 4th server, and get the key sharding */ echo "Adding a new server to the cluster\n"; $cluster = new RedisentCluster(array(array('host' => '127.0.0.1', 'port' => 6379), array('host' => '127.0.0.1', 'port' => 6380), array('host' => '127.0.0.1', 'port' => 6381), array('host' => '127.0.0.1', 'port' => 6382))); /* Try to reset all the keys, and keep track of shards */ $hits = 0; foreach ($keys as $key => $value) { if ($cluster->get($key)) { $hits++; } else { $cluster->set($key, $value); } } /* End tests and print results */ $end_time = microtime(true); echo sprintf("%d key hits (%f%% efficiency)\n", $hits, $hits / count($keys) * 100); echo sprintf("Tests completed in %f seconds\n", $end_time - $start_time);