public function testConnectionStrings() { $this->credis->close(); $this->credis = new Credis_Client('tcp://' . $this->config[0]->host . ':' . $this->config[0]->port); $this->assertEquals($this->credis->getHost(), $this->config[0]->host); $this->assertEquals($this->credis->getPort(), $this->config[0]->port); $this->credis = new Credis_Client('tcp://' . $this->config[0]->host); $this->assertEquals($this->credis->getPort(), $this->config[0]->port); $this->credis = new Credis_Client('tcp://' . $this->config[0]->host . ':' . $this->config[0]->port . '/abc123'); $this->assertEquals('abc123', $this->credis->getPersistence()); $this->credis = new Credis_Client(realpath(__DIR__) . '/redis.sock', 0, null, 'persistent'); $this->credis->connect(); $this->credis->set('key', 'value'); $this->assertEquals('value', $this->credis->get('key')); }
/** * @param Credis_Client $masterClient * @param bool $writeOnly * @return Credis_Cluster */ public function setMasterClient(Credis_Client $masterClient, $writeOnly = false) { if (!$masterClient instanceof Credis_Client) { throw new CredisException('Master client should be an instance of Credis_Client'); } $this->masterClient = $masterClient; if (!isset($this->aliases['master'])) { $this->aliases['master'] = $masterClient; } if (!$writeOnly) { $this->clients[] = $this->masterClient; for ($replica = 0; $replica <= $this->replicas; $replica++) { $md5num = hexdec(substr(md5($this->masterClient->getHost() . ':' . $this->masterClient->getHost() . '-' . $replica), 0, 7)); $this->ring[$md5num] = count($this->clients) - 1; } $this->nodes = array_keys($this->ring); } return $this; }
/** * @return string */ public function getHost() { return $this->_client->getHost(); }