-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify node when sending scan to RedisCluster (#53837)
* Specify node when sending scan to RedisCluster. Default to using the first master node (#53826) * Update src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com> * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com> Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
1 parent
c589439
commit c18b470
Showing
2 changed files
with
123 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Redis\Connections; | ||
|
||
use Illuminate\Redis\Connections\PhpRedisClusterConnection; | ||
use Mockery as m; | ||
use PHPUnit\Framework\Attributes\RequiresPhpExtension; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[RequiresPhpExtension('redis')] | ||
class PhpRedisClusterConnectionTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testItScansUsingDefaultNode() | ||
{ | ||
$client = m::mock(\RedisCluster::class); | ||
$client->shouldReceive('_masters')->once()->andReturn([['127.0.0.1', '6379']]); | ||
$client->shouldReceive('scan') | ||
->once() | ||
->with(0, ['127.0.0.1', '6379'], '*', 10) | ||
->andReturn(['key']); | ||
|
||
$connection = new PhpRedisClusterConnection($client); | ||
$this->assertEquals([0, ['key']], $connection->scan(0)); | ||
} | ||
|
||
public function testItOnlyFetchesDefaultNodeOnce() | ||
{ | ||
$client = m::mock(\RedisCluster::class); | ||
$client->shouldReceive('_masters')->once()->andReturn([['127.0.0.1', '6379']]); | ||
$client->shouldReceive('scan')->twice(); | ||
|
||
$connection = new PhpRedisClusterConnection($client); | ||
$connection->scan(0); | ||
$connection->scan(0); | ||
} | ||
|
||
public function testItScansUsingOptionNode() | ||
{ | ||
$client = m::mock(\RedisCluster::class); | ||
$client->shouldReceive('scan') | ||
->once() | ||
->with(0, 'option-node', '*', 10) | ||
->andReturn(['key']); | ||
|
||
$connection = new PhpRedisClusterConnection($client); | ||
$this->assertEquals([0, ['key']], $connection->scan(0, ['node' => 'option-node'])); | ||
} | ||
|
||
public function testItThrowsExceptionWithoutNodes() | ||
{ | ||
$client = m::mock(\RedisCluster::class); | ||
$client->shouldReceive('_masters')->once()->andReturn([]); | ||
$client->shouldReceive('scan'); | ||
|
||
$this->expectExceptionMessage('Unable to determine default node. No master nodes found in the cluster.'); | ||
|
||
$connection = new PhpRedisClusterConnection($client); | ||
$connection->scan(0); | ||
} | ||
} |