Skip to content

Commit

Permalink
port changes from v1.1 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed May 26, 2022
1 parent a5ab2bc commit b060d43
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function parseResponse($data)
*/
public static function normalizeArguments(array $arguments)
{
if (count($arguments) === 1 && is_array($arguments[0])) {
if (count($arguments) === 1 && isset($arguments[0]) && is_array($arguments[0])) {
return $arguments[0];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Processor/ProcessorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getProcessors()
/**
* Returns an iterator over the list of command processor in the chain.
*
* @return \ArrayIterator
* @return \Traversable<int, ProcessorInterface>
*/
public function getIterator()
{
Expand Down
8 changes: 6 additions & 2 deletions src/CommunicationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public function __construct(
$code = 0,
\Exception $innerException = null
) {
$this->connection = $connection;
parent::__construct(
is_null($message) ? '' : $message,
is_null($code) ? 0 : $code,
$innerException
);

parent::__construct($message, $code, $innerException);
$this->connection = $connection;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Connection/PhpiredisSocketConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function __construct(ParametersInterface $parameters)
*/
public function __destruct()
{
phpiredis_reader_destroy($this->reader);

parent::__destruct();

phpiredis_reader_destroy($this->reader);
}

/**
Expand Down Expand Up @@ -342,7 +342,9 @@ public function connect()
public function disconnect()
{
if ($this->isConnected()) {
phpiredis_reader_reset($this->reader);
socket_close($this->getResource());

parent::disconnect();
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/Connection/PhpiredisStreamConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ public function __construct(ParametersInterface $parameters)
*/
public function __destruct()
{
parent::__destruct();

phpiredis_reader_destroy($this->reader);
}

parent::__destruct();
/**
* {@inheritdoc}
*/
public function disconnect()
{
phpiredis_reader_reset($this->reader);

parent::disconnect();
}

/**
Expand Down
26 changes: 17 additions & 9 deletions src/Connection/Replication/SentinelReplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Predis\Connection\Parameters;
use Predis\Replication\ReplicationStrategy;
use Predis\Replication\RoleException;
use Predis\Response\Error;
use Predis\Response\ErrorInterface as ErrorResponseInterface;
use Predis\Response\ServerException;

Expand Down Expand Up @@ -151,14 +152,14 @@ public function setRetryLimit($retry)
}

/**
* Sets the time to wait (in seconds) before fetching a new configuration
* Sets the time to wait (in milliseconds) before fetching a new configuration
* from one of the sentinels.
*
* @param float $seconds Time to wait before the next attempt.
* @param float $milliseconds Time to wait before the next attempt.
*/
public function setRetryWait($seconds)
public function setRetryWait($milliseconds)
{
$this->retryWait = (float) $seconds;
$this->retryWait = (float) $milliseconds;
}

/**
Expand Down Expand Up @@ -254,12 +255,15 @@ protected function createSentinelConnection($parameters)
}

if (is_array($parameters)) {
// Password authentication is fine now that Redis Sentinel supports
// password-protected sentinel instances, but we must explicitly set
// "database" and "username" to NULL so that no augmented AUTH (ACL)
// and SELECT command are sent by accident to the sentinels.
// NOTE: sentinels do not accept AUTH and SELECT commands so we must
// explicitly set them to NULL to avoid problems when using default
// parameters set via client options. Actually AUTH is supported for
// sentinels starting with Redis 5 but we have to differentiate from
// sentinels passwords and nodes passwords, this will be implemented
// in a later release.
$parameters['database'] = null;
$parameters['username'] = null;
$parameters['password'] = null;

if (!isset($parameters['timeout'])) {
$parameters['timeout'] = $this->sentinelTimeout;
Expand Down Expand Up @@ -534,13 +538,17 @@ private function getConnectionInternal(CommandInterface $command)
* @param NodeConnectionInterface $connection Connection to a redis server.
* @param string $role Expected role of the server ("master", "slave" or "sentinel").
*
* @throws RoleException
* @throws RoleException|ConnectionException
*/
protected function assertConnectionRole(NodeConnectionInterface $connection, $role)
{
$role = strtolower($role);
$actualRole = $connection->executeCommand(RawCommand::create('ROLE'));

if ($actualRole instanceof Error) {
throw new ConnectionException($connection, $actualRole->getMessage());
}

if ($role !== $actualRole[0]) {
throw new RoleException($connection, "Expected $role but got $actualRole[0] [$connection]");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/StreamConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function writeRequest(CommandInterface $command)
$buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n";

foreach ($arguments as $argument) {
$arglen = strlen($argument);
$arglen = strlen(strval($argument));
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}

Expand Down
6 changes: 6 additions & 0 deletions src/Session/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function register()
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function open($save_path, $session_id)
{
// NOOP
Expand All @@ -63,6 +64,7 @@ public function open($save_path, $session_id)
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function close()
{
// NOOP
Expand All @@ -72,6 +74,7 @@ public function close()
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
// NOOP
Expand All @@ -81,6 +84,7 @@ public function gc($maxlifetime)
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function read($session_id)
{
if ($data = $this->client->get($session_id)) {
Expand All @@ -92,6 +96,7 @@ public function read($session_id)
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function write($session_id, $session_data)
{
$this->client->setex($session_id, $this->ttl, $session_data);
Expand All @@ -102,6 +107,7 @@ public function write($session_id, $session_data)
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function destroy($session_id)
{
$this->client->del($session_id);
Expand Down
3 changes: 2 additions & 1 deletion src/Transaction/AbortedMultiExecException.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class AbortedMultiExecException extends PredisException
*/
public function __construct(MultiExec $transaction, $message, $code = 0)
{
parent::__construct($message, $code);
parent::__construct($message, is_null($code) ? 0 : $code);

$this->transaction = $transaction;
}

Expand Down

0 comments on commit b060d43

Please sign in to comment.