Skip to content

Commit

Permalink
Merge pull request #160 from Xon/php8.1
Browse files Browse the repository at this point in the history
php8.1 compat fix for socket connection strings & phpredis
  • Loading branch information
colinmollenhour committed Mar 8, 2022
2 parents b4ca840 + c3622c1 commit 77e6ede
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
vendor
phpunit.phar
phpunit_*.log
/.phpunit.result.cache
8 changes: 4 additions & 4 deletions Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Credis_Client {

/**
* Port on which the Redis server is running
* @var integer
* @var integer|null
*/
protected $port;

Expand Down Expand Up @@ -358,7 +358,7 @@ public function getHost()
}
/**
* Return the port of the Redis instance
* @return int
* @return int|null
*/
public function getPort()
{
Expand Down Expand Up @@ -474,8 +474,8 @@ public function connect()
try
{
$result = $this->persistent
? $this->redis->pconnect($this->host, $this->port, $socketTimeout, $this->persistent)
: $this->redis->connect($this->host, $this->port, $socketTimeout);
? $this->redis->pconnect($this->host, (int)$this->port, $socketTimeout, $this->persistent)
: $this->redis->connect($this->host, (int)$this->port, $socketTimeout);
}
catch(Exception $e)
{
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=5.6.0"
},
"suggest": {
"ext-redis": "Improved performance for communicating with redis"
},
"autoload": {
"classmap": [
Expand Down
13 changes: 0 additions & 13 deletions tests/CredisStandaloneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ class CredisStandaloneTest extends CredisTest
{
protected $useStandalone = TRUE;

/**
* @group UnixSocket
*/
public function testInvalidPersistentConnectionOnUnixSocket()
{
$this->credis->close();
$this->credis = new Credis_Client('unix://'.realpath(__DIR__).'/redis.sock',0,null,'persistent');
$this->credis->forceStandalone();
//$this->setExpectedException('CredisException','Persistent connections to UNIX sockets are not supported in standalone mode.');
$this->credis->connect();
$this->assertTrue($this->credis->isConnected());
}

public function testPersistentConnectionsOnStandAloneTcpConnection()
{
$this->credis->close();
Expand Down
6 changes: 5 additions & 1 deletion tests/CredisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,12 @@ public function testConnectionStringsTls()
*/
public function testConnectionStringsSocket()
{
$this->credis = new Credis_Client(realpath(__DIR__).'/redis.sock',0,null,'persistent');
$this->credis = new Credis_Client(realpath(__DIR__).'/redis.sock');
if ($this->useStandalone) {
$this->credis->forceStandalone();
}
$this->credis->connect();
$this->assertTrue($this->credis->isConnected());
$this->credis->set('key','value');
$this->assertEquals('value',$this->credis->get('key'));
}
Expand All @@ -708,6 +709,9 @@ public function testInvalidTlsConnectionString()
}
}

/**
* @group UnixSocket
*/
public function testInvalidUnixSocketConnectionString()
{
$this->credis->close();
Expand Down

0 comments on commit 77e6ede

Please sign in to comment.