-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.x] Normalize scheme in Redis connections (#33892)
* Normalize scheme in Redis connections * Map `redis` and `rediss` schemes to `tcp` and `tls`
- Loading branch information
Showing
5 changed files
with
230 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Redis; | ||
|
||
use Illuminate\Foundation\Application; | ||
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; | ||
use Illuminate\Redis\RedisManager; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RedisConnectorTest extends TestCase | ||
{ | ||
use InteractsWithRedis; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->setUpRedis(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->tearDownRedis(); | ||
|
||
m::close(); | ||
} | ||
|
||
public function testDefaultConfiguration() | ||
{ | ||
$host = env('REDIS_HOST', '127.0.0.1'); | ||
$port = env('REDIS_PORT', 6379); | ||
|
||
$predisClient = $this->redis['predis']->connection()->client(); | ||
$parameters = $predisClient->getConnection()->getParameters(); | ||
$this->assertEquals('tcp', $parameters->scheme); | ||
$this->assertEquals($host, $parameters->host); | ||
$this->assertEquals($port, $parameters->port); | ||
|
||
$phpRedisClient = $this->redis['phpredis']->connection()->client(); | ||
$this->assertEquals($host, $phpRedisClient->getHost()); | ||
$this->assertEquals($port, $phpRedisClient->getPort()); | ||
} | ||
|
||
public function testUrl() | ||
{ | ||
$host = env('REDIS_HOST', '127.0.0.1'); | ||
$port = env('REDIS_PORT', 6379); | ||
|
||
$predis = new RedisManager(new Application, 'predis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'url' => "redis://{$host}:{$port}", | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$predisClient = $predis->connection()->client(); | ||
$parameters = $predisClient->getConnection()->getParameters(); | ||
$this->assertEquals('tcp', $parameters->scheme); | ||
$this->assertEquals($host, $parameters->host); | ||
$this->assertEquals($port, $parameters->port); | ||
|
||
$phpRedis = new RedisManager(new Application, 'phpredis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'url' => "redis://{$host}:{$port}", | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$phpRedisClient = $phpRedis->connection()->client(); | ||
$this->assertEquals("tcp://{$host}", $phpRedisClient->getHost()); | ||
$this->assertEquals($port, $phpRedisClient->getPort()); | ||
} | ||
|
||
public function testUrlWithScheme() | ||
{ | ||
$host = env('REDIS_HOST', '127.0.0.1'); | ||
$port = env('REDIS_PORT', 6379); | ||
|
||
$predis = new RedisManager(new Application, 'predis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'url' => "tls://{$host}:{$port}", | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$predisClient = $predis->connection()->client(); | ||
$parameters = $predisClient->getConnection()->getParameters(); | ||
$this->assertEquals('tls', $parameters->scheme); | ||
$this->assertEquals($host, $parameters->host); | ||
$this->assertEquals($port, $parameters->port); | ||
|
||
$phpRedis = new RedisManager(new Application, 'phpredis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'url' => "tcp://{$host}:{$port}", | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$phpRedisClient = $phpRedis->connection()->client(); | ||
$this->assertEquals("tcp://{$host}", $phpRedisClient->getHost()); | ||
$this->assertEquals($port, $phpRedisClient->getPort()); | ||
} | ||
|
||
public function testScheme() | ||
{ | ||
$host = env('REDIS_HOST', '127.0.0.1'); | ||
$port = env('REDIS_PORT', 6379); | ||
|
||
$predis = new RedisManager(new Application, 'predis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'scheme' => 'tls', | ||
'host' => $host, | ||
'port' => $port, | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$predisClient = $predis->connection()->client(); | ||
$parameters = $predisClient->getConnection()->getParameters(); | ||
$this->assertEquals('tls', $parameters->scheme); | ||
$this->assertEquals($host, $parameters->host); | ||
$this->assertEquals($port, $parameters->port); | ||
|
||
$phpRedis = new RedisManager(new Application, 'phpredis', [ | ||
'cluster' => false, | ||
'options' => [ | ||
'prefix' => 'test_', | ||
], | ||
'default' => [ | ||
'scheme' => 'tcp', | ||
'host' => $host, | ||
'port' => $port, | ||
'database' => 5, | ||
'timeout' => 0.5, | ||
], | ||
]); | ||
$phpRedisClient = $phpRedis->connection()->client(); | ||
$this->assertEquals("tcp://{$host}", $phpRedisClient->getHost()); | ||
$this->assertEquals($port, $phpRedisClient->getPort()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters