mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
Fixed Sentinel getParameters() executed on string configuration (#1649)
This commit is contained in:
committed by
GitHub
parent
0850f2f36e
commit
274cb866bd
@@ -1,4 +1,6 @@
|
||||
## Changelog
|
||||
## Unreleased
|
||||
- Fixed Sentinel getParameters() executed on string configuration (#1649)
|
||||
|
||||
## v3.4.1 (2026-02-23)
|
||||
### Added
|
||||
|
||||
@@ -75,7 +75,15 @@ class SentinelReplication extends AbstractAggregateConnection implements Replica
|
||||
protected $strategy;
|
||||
|
||||
/**
|
||||
* @var NodeConnectionInterface[]
|
||||
* Sentinel connection parameters.
|
||||
*
|
||||
* Can contain:
|
||||
* - String URIs (e.g., "tcp://127.0.0.1:26379")
|
||||
* - Arrays of connection parameters (e.g., ['host' => '127.0.0.1', 'port' => 26379])
|
||||
* - ParametersInterface objects
|
||||
* - NodeConnectionInterface objects
|
||||
*
|
||||
* @var array<string|array|ParametersInterface|NodeConnectionInterface>
|
||||
*/
|
||||
protected $sentinels = [];
|
||||
|
||||
@@ -811,6 +819,11 @@ class SentinelReplication extends AbstractAggregateConnection implements Replica
|
||||
if (!empty($this->sentinels)) {
|
||||
$sentinel = $this->sentinels[0];
|
||||
|
||||
// Handle string URIs (e.g., "tcp://127.0.0.1:26379")
|
||||
if (is_string($sentinel)) {
|
||||
return new Parameters(Parameters::parse($sentinel));
|
||||
}
|
||||
|
||||
// After querySentinels(), sentinels array contains plain arrays instead of connection objects
|
||||
if (is_array($sentinel)) {
|
||||
return new Parameters($sentinel);
|
||||
|
||||
@@ -17,6 +17,7 @@ use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Predis\Command;
|
||||
use Predis\Connection;
|
||||
use Predis\Connection\Parameters;
|
||||
use Predis\Connection\ParametersInterface;
|
||||
use Predis\Connection\Resource\StreamFactoryInterface;
|
||||
use Predis\Connection\StreamConnection;
|
||||
use Predis\Replication;
|
||||
@@ -1762,6 +1763,24 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
$this->assertNull($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetParametersHandlesStringUriInSentinelsArray(): void
|
||||
{
|
||||
// Test with string URI (e.g., "tcp://127.0.0.1:26379")
|
||||
$sentinelUri = 'tcp://127.0.0.1:5381?role=sentinel';
|
||||
|
||||
$replication = $this->getReplicationConnection('srv', [$sentinelUri]);
|
||||
|
||||
$parameters = $replication->getParameters();
|
||||
|
||||
$this->assertInstanceOf(ParametersInterface::class, $parameters);
|
||||
$this->assertSame('127.0.0.1', $parameters->host);
|
||||
$this->assertSame(5381, $parameters->port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user