Ejemplo n.º 1
0
 public function testSetMasterClient()
 {
     $this->tearDown();
     $master = new Credis_Client($this->config[0]['host'], $this->config[0]['port']);
     $slave = new Credis_Client($this->config[6]['host'], $this->config[6]['port']);
     $this->cluster = new Credis_Cluster(array($slave), 2, $this->useStandalone);
     $this->assertInstanceOf('Credis_Cluster', $this->cluster->setMasterClient($master));
     $this->assertCount(2, $this->cluster->clients());
     $this->assertEquals($this->config[6]['port'], $this->cluster->client(0)->getPort());
     $this->assertEquals($this->config[0]['port'], $this->cluster->client('master')->getPort());
     $this->cluster = new Credis_Cluster(array($this->config[0]), 2, $this->useStandalone);
     $this->assertInstanceOf('Credis_Cluster', $this->cluster->setMasterClient(new Credis_Client($this->config[1]['host'], $this->config[1]['port'])));
     $this->assertEquals($this->config[0]['port'], $this->cluster->client('master')->getPort());
     $this->cluster = new Credis_Cluster(array($slave), 2, $this->useStandalone);
     $this->assertInstanceOf('Credis_Cluster', $this->cluster->setMasterClient($master, true));
     $this->assertCount(1, $this->cluster->clients());
 }
Ejemplo n.º 2
0
$keys = array();
$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];
    }
}
printf("Setting %d keys\n", count($keys));
$cluster->all('flushDb');
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 Credis_Cluster(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)), $replicas);
/* Try to reset all the keys, and keep track of shards */
$hits = 0;
foreach ($keys as $key => $value) {
    if ($cluster->get($key)) {
        $hits++;
    }
}
foreach ($cluster->all('info') as $info) {
    if (isset($info['db0'])) {
        echo "{$info['db0']}\n";
    }
}
/* End tests and print results */
printf("%d key hits (%f%% efficiency)\n", $hits, $hits / count($keys) * 100);
printf("Tests completed in %f seconds\n", microtime(true) - $start_time);