Skip to content

Commit dc20027

Browse files
Fixes connectionStrings parsing (#141)
* 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 <colin@mollenhour.com>
1 parent e217dc3 commit dc20027

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ protected function convertHost()
423423
throw new CredisException('Invalid host format; expected '.$this->scheme.'://host[:port][/persistence_identifier]');
424424
}
425425
$this->host = $matches[1];
426-
$this->port = (int) (isset($matches[3]) ? $matches[3] : 6379);
427-
$this->persistent = isset($matches[5]) ? $matches[5] : '';
426+
$this->port = (int) (isset($matches[3]) ? $matches[3] : $this->port);
427+
$this->persistent = isset($matches[5]) ? $matches[5] : $this->persistent;
428428
} else {
429429
$this->host = $matches[2];
430430
$this->port = NULL;

tests/CredisTest.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -631,44 +631,32 @@ public function testGettersAndSetters()
631631

632632
public function testConnectionStrings()
633633
{
634-
$this->credis->close();
635634
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port']);
636-
if ($this->useStandalone) {
637-
$this->credis->forceStandalone();
638-
}
639635
$this->assertEquals($this->credis->getHost(),$this->redisConfig[0]['host']);
640636
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
641637
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host']);
642-
if ($this->useStandalone) {
643-
$this->credis->forceStandalone();
644-
}
645-
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
638+
$this->assertEquals($this->credis->getPort(),6379);
646639
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port'] . '/abc123');
647-
if ($this->useStandalone) {
648-
$this->credis->forceStandalone();
649-
}
650-
$this->assertEquals('abc123',$this->credis->getPersistence());
640+
$this->assertEquals($this->credis->getPersistence(),'abc123');
641+
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'],6380);
642+
$this->assertEquals($this->credis->getPort(),6380);
643+
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'],NULL,NULL,"abc123");
644+
$this->assertEquals($this->credis->getPersistence(),'abc123');
651645
}
652646

653647
public function testConnectionStringsTls()
654648
{
655-
$this->credis->close();
656649
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port']);
657-
if ($this->useStandalone) {
658-
$this->credis->forceStandalone();
659-
}
660650
$this->assertEquals($this->credis->getHost(),$this->redisConfig[0]['host']);
661651
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
662652
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host']);
663-
if ($this->useStandalone) {
664-
$this->credis->forceStandalone();
665-
}
666-
$this->assertEquals($this->credis->getPort(),$this->redisConfig[0]['port']);
653+
$this->assertEquals($this->credis->getPort(),6379);
667654
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'] . ':' . $this->redisConfig[0]['port'] . '/abc123');
668-
if ($this->useStandalone) {
669-
$this->credis->forceStandalone();
670-
}
671-
$this->assertEquals('abc123',$this->credis->getPersistence());
655+
$this->assertEquals($this->credis->getPersistence(),'abc123');
656+
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'],6380);
657+
$this->assertEquals($this->credis->getPort(),6380);
658+
$this->credis = new Credis_Client('tls://'.$this->redisConfig[0]['host'],NULL,NULL,"abc123");
659+
$this->assertEquals($this->credis->getPersistence(),'abc123');
672660
}
673661

674662
/**

0 commit comments

Comments
 (0)