/** * @group disconnected */ public function testDefineAndUndefineConnection() { list(, $connectionClass) = $this->getMockConnectionClass(); $factory = new ConnectionFactory(); $factory->define('redis', $connectionClass); $this->assertInstanceOf($connectionClass, $factory->create('redis://127.0.0.1')); $factory->undefine('redis'); $this->setExpectedException('InvalidArgumentException', 'Unknown connection scheme: redis'); $factory->create('redis://127.0.0.1'); }
private function createConnection($parameters) { $params = null; $connection = null; if ($parameters instanceof IConnectionSingle) { $connection = $parameters; $params = $connection->getParameters(); } else { $params = $parameters instanceof ConnectionParameters ? $parameters : new ConnectionParameters($parameters); $connection = ConnectionFactory::create($params, $this->_responseReader); } return $this->pushInitCommands($connection, $params); }
/** * @group disconnected */ public function testConstructorWithConnectionArgument() { $factory = new ConnectionFactory(); $connection = $factory->create('tcp://localhost:7000'); $client = new Client($connection); $this->assertInstanceOf('Predis\\Network\\IConnectionSingle', $client->getConnection()); $this->assertSame($connection, $client->getConnection()); $parameters = $client->getConnection()->getParameters(); $this->assertSame($parameters->host, 'localhost'); $this->assertSame($parameters->port, 7000); }
private function createConnection($parameters) { $params = $parameters instanceof ConnectionParameters ? $parameters : new ConnectionParameters($parameters); $connection = ConnectionFactory::create($params, $this->_responseReader); if ($params->password !== null) { $connection->pushInitCommand($this->createCommand('auth', array($params->password))); } if ($params->database !== null) { $connection->pushInitCommand($this->createCommand('changedb', array($params->database))); } return $connection; }
/** * {@inheritdoc} */ public function create($parameters, IServerProfile $profile = null) { $connection = parent::create($parameters, $profile); $connection = new LoggableConection($connection, $this->logger); return $connection; }
/** * {@inheritdoc} */ public function create($parameters, IServerProfile $profile = null) { $connection = parent::create($parameters); if ($connection->getParameters()->logging) { if (null !== $this->wrapper) { $wrapper = $this->wrapper; $connection = new $wrapper($connection); } $connection->setLogger($this->logger); } return $connection; }