public function testGetSetConnection() { $redisBackend = new Backend\Redis(); $this->assertFalse($redisBackend->getConnection()->getHost(), 'Connection was not reset'); $redisBackend->setConnection($this->redis); $this->assertEquals($this->redis, $redisBackend->getConnection(), 'Connection was not set correctly'); }
/** * Connect to specified host and port * * @param string $host Host * @param int $port Port * @param int $timeout Connection timeout * * @return null */ public function connect($host = null, $port = null, $timeout = 0) { $host = $host ?: $this->getConnection()->getHost(); $port = $port ?: $this->getConnection()->getPort(); $this->options['host'] = $host; $this->options['port'] = $port; $this->options['timeout'] = $timeout; $dbNum = isset($this->options['dbNum']) ? $this->options['dbNum'] : $this->getDbNum(); $this->connection->connect($host, $port, $timeout); if ($this->getAuth() !== null) { //reauth connection after new connect $this->setAuth($this->getAuth()); } if ($dbNum != 0) { $this->setDbNum($dbNum); } }