Skip to content

Commit

Permalink
Fixes connectionStrings parsing (#141)
Browse files Browse the repository at this point in the history
* travis has built-in redis-server 6.0.5

- make downloaded redis-server PATH priority higher then built-in one

* Fixes connectionStrings parsing

- Fixes port always be 6379 even no port specified in host string and specified the port number other then 6379 in constructor
- Fixes persistent too

* Added test cases

- Code Cleanup

Co-authored-by: Colin Mollenhour <[email protected]>
  • Loading branch information
akunzai and colinmollenhour committed Oct 12, 2020
1 parent e217dc3 commit dc20027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ protected function convertHost()
throw new CredisException('Invalid host format; expected '.$this->scheme.'://host[:port][/persistence_identifier]');
}
$this->host = $matches[1];
$this->port = (int) (isset($matches[3]) ? $matches[3] : 6379);
$this->persistent = isset($matches[5]) ? $matches[5] : '';
$this->port = (int) (isset($matches[3]) ? $matches[3] : $this->port);
$this->persistent = isset($matches[5]) ? $matches[5] : $this->persistent;
} else {
$this->host = $matches[2];
$this->port = NULL;
Expand Down
36 changes: 12 additions & 24 deletions tests/CredisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,44 +631,32 @@ public function testGettersAndSetters()

public function testConnectionStrings()
{
$this->credis->close();
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port']);
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals($this->credis->getHost(),$this->redisConfig[0]['host']);
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host']);
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
$this->assertEquals($this->credis->getPort(),6379);
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port'] . '/abc123');
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals('abc123',$this->credis->getPersistence());
$this->assertEquals($this->credis->getPersistence(),'abc123');
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'],6380);
$this->assertEquals($this->credis->getPort(),6380);
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'],NULL,NULL,"abc123");
$this->assertEquals($this->credis->getPersistence(),'abc123');
}

public function testConnectionStringsTls()
{
$this->credis->close();
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port']);
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals($this->credis->getHost(),$this->redisConfig[0]['host']);
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host']);
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
$this->assertEquals($this->credis->getPort(),6379);
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port'] . '/abc123');
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->assertEquals('abc123',$this->credis->getPersistence());
$this->assertEquals($this->credis->getPersistence(),'abc123');
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'],6380);
$this->assertEquals($this->credis->getPort(),6380);
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'],NULL,NULL,"abc123");
$this->assertEquals($this->credis->getPersistence(),'abc123');
}

/**
Expand Down

0 comments on commit dc20027

Please sign in to comment.