diff --git a/CHANGELOG.md b/CHANGELOG.md
index b26e739e..fd468fff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
## Changelog
+## Unreleased
+
+### Changed
+- Added `PrefixableCommandInterface` (#1262)
+
+### Removed
+- Removed Webdis and Phpiredis support (#1291)
+
## v2.2.0-RC1 (2023-05-09)
### Added
diff --git a/phpstan.dist.neon b/phpstan.dist.neon
index f7bb09a5..b9df88b3 100644
--- a/phpstan.dist.neon
+++ b/phpstan.dist.neon
@@ -12,9 +12,6 @@ parameters:
- message: "#^Cannot cast Predis\\\\Connection\\\\ConnectionInterface to string\\.$#"
count: 1
path: src/Client.php
- # phpiredis extension is not installed
- - "#^Function phpiredis_\\w+ not found\\.$#"
- - "#^Constant PHPIREDIS_#"
# "new static" in non-final classes
- message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 3
diff --git a/phpunit.relay.xml b/phpunit.relay.xml
index 731f29c2..bfe4f52a 100644
--- a/phpunit.relay.xml
+++ b/phpunit.relay.xml
@@ -20,10 +20,8 @@
relay-incompatible
- realm-webdis
realm-stack
ext-curl
- ext-phpiredis
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d47afa8d..662e1fd4 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -28,11 +28,9 @@
- realm-webdis
realm-stack
ext-relay
ext-curl
- ext-phpiredis
diff --git a/src/Cluster/Hash/PhpiredisCRC16.php b/src/Cluster/Hash/PhpiredisCRC16.php
deleted file mode 100644
index 04f58a0e..00000000
--- a/src/Cluster/Hash/PhpiredisCRC16.php
+++ /dev/null
@@ -1,42 +0,0 @@
-getDefault($options);
switch (strtolower($value)) {
- case 'phpiredis':
- case 'phpiredis-stream':
- $factory->define('tcp', PhpiredisStreamConnection::class);
- $factory->define('redis', PhpiredisStreamConnection::class);
- $factory->define('unix', PhpiredisStreamConnection::class);
- break;
-
- case 'phpiredis-socket':
- $factory->define('tcp', PhpiredisSocketConnection::class);
- $factory->define('redis', PhpiredisSocketConnection::class);
- $factory->define('unix', PhpiredisSocketConnection::class);
- break;
-
case 'relay':
$factory->define('tcp', RelayConnection::class);
$factory->define('redis', RelayConnection::class);
diff --git a/src/Connection/Factory.php b/src/Connection/Factory.php
index ad472360..7647af53 100644
--- a/src/Connection/Factory.php
+++ b/src/Connection/Factory.php
@@ -30,7 +30,6 @@ class Factory implements FactoryInterface
'tls' => 'Predis\Connection\StreamConnection',
'redis' => 'Predis\Connection\StreamConnection',
'rediss' => 'Predis\Connection\StreamConnection',
- 'http' => 'Predis\Connection\WebdisConnection',
];
/**
diff --git a/src/Connection/PhpiredisSocketConnection.php b/src/Connection/PhpiredisSocketConnection.php
deleted file mode 100644
index 6ff1f77b..00000000
--- a/src/Connection/PhpiredisSocketConnection.php
+++ /dev/null
@@ -1,420 +0,0 @@
-assertExtensions();
-
- parent::__construct($parameters);
-
- $this->reader = $this->createReader();
- }
-
- /**
- * Disconnects from the server and destroys the underlying resource and the
- * protocol reader resource when PHP's garbage collector kicks in.
- */
- public function __destruct()
- {
- parent::__destruct();
-
- phpiredis_reader_destroy($this->reader);
- }
-
- /**
- * Checks if the socket and phpiredis extensions are loaded in PHP.
- */
- protected function assertExtensions()
- {
- if (!extension_loaded('sockets')) {
- throw new NotSupportedException(
- 'The "sockets" extension is required by this connection backend.'
- );
- }
-
- if (!extension_loaded('phpiredis')) {
- throw new NotSupportedException(
- 'The "phpiredis" extension is required by this connection backend.'
- );
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function assertParameters(ParametersInterface $parameters)
- {
- switch ($parameters->scheme) {
- case 'tcp':
- case 'redis':
- case 'unix':
- break;
-
- default:
- throw new InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
- }
-
- if (isset($parameters->persistent)) {
- throw new NotSupportedException(
- 'Persistent connections are not supported by this connection backend.'
- );
- }
-
- return $parameters;
- }
-
- /**
- * Creates a new instance of the protocol reader resource.
- *
- * @return resource
- */
- private function createReader()
- {
- $reader = phpiredis_reader_create();
-
- phpiredis_reader_set_status_handler($reader, $this->getStatusHandler());
- phpiredis_reader_set_error_handler($reader, $this->getErrorHandler());
-
- return $reader;
- }
-
- /**
- * Returns the underlying protocol reader resource.
- *
- * @return resource
- */
- protected function getReader()
- {
- return $this->reader;
- }
-
- /**
- * Returns the handler used by the protocol reader for inline responses.
- *
- * @return Closure
- */
- protected function getStatusHandler()
- {
- static $statusHandler;
-
- if (!$statusHandler) {
- $statusHandler = function ($payload) {
- return StatusResponse::get($payload);
- };
- }
-
- return $statusHandler;
- }
-
- /**
- * Returns the handler used by the protocol reader for error responses.
- *
- * @return Closure
- */
- protected function getErrorHandler()
- {
- static $errorHandler;
-
- if (!$errorHandler) {
- $errorHandler = function ($errorMessage) {
- return new ErrorResponse($errorMessage);
- };
- }
-
- return $errorHandler;
- }
-
- /**
- * Helper method used to throw exceptions on socket errors.
- */
- private function emitSocketError()
- {
- $errno = socket_last_error();
- $errstr = socket_strerror($errno);
-
- $this->disconnect();
-
- $this->onConnectionError(trim($errstr), $errno);
- }
-
- /**
- * Gets the address of an host from connection parameters.
- *
- * @param ParametersInterface $parameters Parameters used to initialize the connection.
- *
- * @return string
- */
- protected static function getAddress(ParametersInterface $parameters)
- {
- if (filter_var($host = $parameters->host, FILTER_VALIDATE_IP)) {
- return $host;
- }
-
- if ($host === $address = gethostbyname($host)) {
- return false;
- }
-
- return $address;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function createResource()
- {
- $parameters = $this->parameters;
-
- if ($parameters->scheme === 'unix') {
- $address = $parameters->path;
- $domain = AF_UNIX;
- $protocol = 0;
- } else {
- if (false === $address = self::getAddress($parameters)) {
- $this->onConnectionError("Cannot resolve the address of '$parameters->host'.");
- }
-
- $domain = filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? AF_INET6 : AF_INET;
- $protocol = SOL_TCP;
- }
-
- if (false === $socket = @socket_create($domain, SOCK_STREAM, $protocol)) {
- $this->emitSocketError();
- }
-
- $this->setSocketOptions($socket, $parameters);
- $this->connectWithTimeout($socket, $address, $parameters);
-
- return $socket;
- }
-
- /**
- * Sets options on the socket resource from the connection parameters.
- *
- * @param resource $socket Socket resource.
- * @param ParametersInterface $parameters Parameters used to initialize the connection.
- */
- private function setSocketOptions($socket, ParametersInterface $parameters)
- {
- if ($parameters->scheme !== 'unix') {
- if (!socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1)) {
- $this->emitSocketError();
- }
-
- if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
- $this->emitSocketError();
- }
- }
-
- if (isset($parameters->read_write_timeout)) {
- $rwtimeout = (float) $parameters->read_write_timeout;
- $timeoutSec = floor($rwtimeout);
- $timeoutUsec = ($rwtimeout - $timeoutSec) * 1000000;
-
- $timeout = [
- 'sec' => $timeoutSec,
- 'usec' => $timeoutUsec,
- ];
-
- if (!socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout)) {
- $this->emitSocketError();
- }
-
- if (!socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout)) {
- $this->emitSocketError();
- }
- }
- }
-
- /**
- * Opens the actual connection to the server with a timeout.
- *
- * @param resource $socket Socket resource.
- * @param string $address IP address (DNS-resolved from hostname)
- * @param ParametersInterface $parameters Parameters used to initialize the connection.
- *
- * @return void
- */
- private function connectWithTimeout($socket, $address, ParametersInterface $parameters)
- {
- socket_set_nonblock($socket);
-
- if (@socket_connect($socket, $address, (int) $parameters->port) === false) {
- $error = socket_last_error();
-
- if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
- $this->emitSocketError();
- }
- }
-
- socket_set_block($socket);
-
- $null = null;
- $selectable = [$socket];
-
- $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
- $timeoutSecs = floor($timeout);
- $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000;
-
- $selected = socket_select($selectable, $selectable, $null, $timeoutSecs, $timeoutUSecs);
-
- if ($selected === 2) {
- $this->onConnectionError('Connection refused.', SOCKET_ECONNREFUSED);
- }
-
- if ($selected === 0) {
- $this->onConnectionError('Connection timed out.', SOCKET_ETIMEDOUT);
- }
-
- if ($selected === false) {
- $this->emitSocketError();
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function connect()
- {
- if (parent::connect() && $this->initCommands) {
- foreach ($this->initCommands as $command) {
- $response = $this->executeCommand($command);
-
- if ($response instanceof ErrorResponseInterface) {
- $this->onConnectionError("`{$command->getId()}` failed: {$response->getMessage()}", 0);
- }
- }
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function disconnect()
- {
- if ($this->isConnected()) {
- phpiredis_reader_reset($this->reader);
- socket_close($this->getResource());
-
- parent::disconnect();
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function write($buffer)
- {
- $socket = $this->getResource();
-
- while (($length = strlen($buffer)) > 0) {
- $written = socket_write($socket, $buffer, $length);
-
- if ($length === $written) {
- return;
- }
-
- if ($written === false) {
- $this->onConnectionError('Error while writing bytes to the server.');
- }
-
- $buffer = substr($buffer, $written);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function read()
- {
- $socket = $this->getResource();
- $reader = $this->reader;
-
- while (PHPIREDIS_READER_STATE_INCOMPLETE === $state = phpiredis_reader_get_state($reader)) {
- if (@socket_recv($socket, $buffer, 4096, 0) === false || $buffer === '' || $buffer === null) {
- $this->emitSocketError();
- }
-
- phpiredis_reader_feed($reader, $buffer);
- }
-
- if ($state === PHPIREDIS_READER_STATE_COMPLETE) {
- return phpiredis_reader_get_reply($reader);
- } else {
- $this->onProtocolError(phpiredis_reader_get_error($reader));
-
- return;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function writeRequest(CommandInterface $command)
- {
- $arguments = $command->getArguments();
- array_unshift($arguments, $command->getId());
-
- $this->write(phpiredis_format_command($arguments));
- }
-
- /**
- * {@inheritdoc}
- */
- public function __wakeup()
- {
- $this->assertExtensions();
- $this->reader = $this->createReader();
- }
-}
diff --git a/src/Connection/PhpiredisStreamConnection.php b/src/Connection/PhpiredisStreamConnection.php
deleted file mode 100644
index e3dbfd8a..00000000
--- a/src/Connection/PhpiredisStreamConnection.php
+++ /dev/null
@@ -1,262 +0,0 @@
-assertExtensions();
-
- parent::__construct($parameters);
-
- $this->reader = $this->createReader();
- }
-
- /**
- * {@inheritdoc}
- */
- public function __destruct()
- {
- parent::__destruct();
-
- phpiredis_reader_destroy($this->reader);
- }
-
- /**
- * {@inheritdoc}
- */
- public function disconnect()
- {
- phpiredis_reader_reset($this->reader);
-
- parent::disconnect();
- }
-
- /**
- * Checks if the phpiredis extension is loaded in PHP.
- */
- private function assertExtensions()
- {
- if (!extension_loaded('phpiredis')) {
- throw new NotSupportedException(
- 'The "phpiredis" extension is required by this connection backend.'
- );
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function assertParameters(ParametersInterface $parameters)
- {
- switch ($parameters->scheme) {
- case 'tcp':
- case 'redis':
- case 'unix':
- break;
-
- case 'tls':
- case 'rediss':
- throw new InvalidArgumentException('SSL encryption is not supported by this connection backend.');
- default:
- throw new InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
- }
-
- return $parameters;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function createStreamSocket(ParametersInterface $parameters, $address, $flags)
- {
- $socket = null;
- $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
- $context = stream_context_create(['socket' => ['tcp_nodelay' => (bool) $parameters->tcp_nodelay]]);
-
- if (!$resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context)) {
- $this->onConnectionError(trim($errstr), $errno);
- }
-
- if (isset($parameters->read_write_timeout) && function_exists('socket_import_stream')) {
- $rwtimeout = (float) $parameters->read_write_timeout;
- $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1;
-
- $timeout = [
- 'sec' => $timeoutSeconds = floor($rwtimeout),
- 'usec' => ($rwtimeout - $timeoutSeconds) * 1000000,
- ];
-
- $socket = $socket ?: socket_import_stream($resource);
- @socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout);
- @socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);
- }
-
- if (isset($parameters->tcp_nodelay) && function_exists('socket_import_stream')) {
- $socket = $socket ?: socket_import_stream($resource);
- socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int) $parameters->tcp_nodelay);
- }
-
- return $resource;
- }
-
- /**
- * Creates a new instance of the protocol reader resource.
- *
- * @return resource
- */
- private function createReader()
- {
- $reader = phpiredis_reader_create();
-
- phpiredis_reader_set_status_handler($reader, $this->getStatusHandler());
- phpiredis_reader_set_error_handler($reader, $this->getErrorHandler());
-
- return $reader;
- }
-
- /**
- * Returns the underlying protocol reader resource.
- *
- * @return resource
- */
- protected function getReader()
- {
- return $this->reader;
- }
-
- /**
- * Returns the handler used by the protocol reader for inline responses.
- *
- * @return Closure
- */
- protected function getStatusHandler()
- {
- static $statusHandler;
-
- if (!$statusHandler) {
- $statusHandler = function ($payload) {
- return StatusResponse::get($payload);
- };
- }
-
- return $statusHandler;
- }
-
- /**
- * Returns the handler used by the protocol reader for error responses.
- *
- * @return Closure
- */
- protected function getErrorHandler()
- {
- static $errorHandler;
-
- if (!$errorHandler) {
- $errorHandler = function ($errorMessage) {
- return new ErrorResponse($errorMessage);
- };
- }
-
- return $errorHandler;
- }
-
- /**
- * {@inheritdoc}
- */
- public function read()
- {
- $socket = $this->getResource();
- $reader = $this->reader;
-
- while (PHPIREDIS_READER_STATE_INCOMPLETE === $state = phpiredis_reader_get_state($reader)) {
- $buffer = stream_socket_recvfrom($socket, 4096);
-
- if ($buffer === false || $buffer === '') {
- $this->onConnectionError('Error while reading bytes from the server.');
- }
-
- phpiredis_reader_feed($reader, $buffer);
- }
-
- if ($state === PHPIREDIS_READER_STATE_COMPLETE) {
- return phpiredis_reader_get_reply($reader);
- } else {
- $this->onProtocolError(phpiredis_reader_get_error($reader));
-
- return;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function writeRequest(CommandInterface $command)
- {
- $arguments = $command->getArguments();
- array_unshift($arguments, $command->getId());
-
- $this->write(phpiredis_format_command($arguments));
- }
-
- /**
- * {@inheritdoc}
- */
- public function __wakeup()
- {
- $this->assertExtensions();
- $this->reader = $this->createReader();
- }
-}
diff --git a/src/Connection/WebdisConnection.php b/src/Connection/WebdisConnection.php
deleted file mode 100644
index bd533783..00000000
--- a/src/Connection/WebdisConnection.php
+++ /dev/null
@@ -1,366 +0,0 @@
-assertExtensions();
-
- if ($parameters->scheme !== 'http') {
- throw new InvalidArgumentException("Invalid scheme: '{$parameters->scheme}'.");
- }
-
- $this->parameters = $parameters;
-
- $this->resource = $this->createCurl();
- $this->reader = $this->createReader();
- }
-
- /**
- * Frees the underlying cURL and protocol reader resources when the garbage
- * collector kicks in.
- */
- public function __destruct()
- {
- curl_close($this->resource);
- phpiredis_reader_destroy($this->reader);
- }
-
- /**
- * Helper method used to throw on unsupported methods.
- *
- * @param string $method Name of the unsupported method.
- *
- * @throws NotSupportedException
- */
- private function throwNotSupportedException($method)
- {
- $class = __CLASS__;
- throw new NotSupportedException("The method $class::$method() is not supported.");
- }
-
- /**
- * Checks if the cURL and phpiredis extensions are loaded in PHP.
- */
- private function assertExtensions()
- {
- if (!extension_loaded('curl')) {
- throw new NotSupportedException(
- 'The "curl" extension is required by this connection backend.'
- );
- }
-
- if (!extension_loaded('phpiredis')) {
- throw new NotSupportedException(
- 'The "phpiredis" extension is required by this connection backend.'
- );
- }
- }
-
- /**
- * Initializes cURL.
- *
- * @return resource
- */
- private function createCurl()
- {
- $parameters = $this->getParameters();
- $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0) * 1000;
-
- if (filter_var($host = $parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
- $host = "[$host]";
- }
-
- $options = [
- CURLOPT_FAILONERROR => true,
- CURLOPT_CONNECTTIMEOUT_MS => $timeout,
- CURLOPT_URL => "$parameters->scheme://$host:$parameters->port",
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_POST => true,
- CURLOPT_WRITEFUNCTION => [$this, 'feedReader'],
- ];
-
- if (isset($parameters->user, $parameters->pass)) {
- $options[CURLOPT_USERPWD] = "{$parameters->user}:{$parameters->pass}";
- }
-
- curl_setopt_array($resource = curl_init(), $options);
-
- return $resource;
- }
-
- /**
- * Initializes the phpiredis protocol reader.
- *
- * @return resource
- */
- private function createReader()
- {
- $reader = phpiredis_reader_create();
-
- phpiredis_reader_set_status_handler($reader, $this->getStatusHandler());
- phpiredis_reader_set_error_handler($reader, $this->getErrorHandler());
-
- return $reader;
- }
-
- /**
- * Returns the handler used by the protocol reader for inline responses.
- *
- * @return Closure
- */
- protected function getStatusHandler()
- {
- static $statusHandler;
-
- if (!$statusHandler) {
- $statusHandler = function ($payload) {
- return StatusResponse::get($payload);
- };
- }
-
- return $statusHandler;
- }
-
- /**
- * Returns the handler used by the protocol reader for error responses.
- *
- * @return Closure
- */
- protected function getErrorHandler()
- {
- static $errorHandler;
-
- if (!$errorHandler) {
- $errorHandler = function ($errorMessage) {
- return new ErrorResponse($errorMessage);
- };
- }
-
- return $errorHandler;
- }
-
- /**
- * Feeds the phpredis reader resource with the data read from the network.
- *
- * @param resource $resource Reader resource.
- * @param string $buffer Buffer of data read from a connection.
- *
- * @return int
- */
- protected function feedReader($resource, $buffer)
- {
- phpiredis_reader_feed($this->reader, $buffer);
-
- return strlen($buffer);
- }
-
- /**
- * {@inheritdoc}
- */
- public function connect()
- {
- // NOOP
- }
-
- /**
- * {@inheritdoc}
- */
- public function disconnect()
- {
- // NOOP
- }
-
- /**
- * {@inheritdoc}
- */
- public function isConnected()
- {
- return true;
- }
-
- /**
- * Checks if the specified command is supported by this connection class.
- *
- * @param CommandInterface $command Command instance.
- *
- * @return string
- * @throws NotSupportedException
- */
- protected function getCommandId(CommandInterface $command)
- {
- switch ($commandID = $command->getId()) {
- case 'AUTH':
- case 'SELECT':
- case 'MULTI':
- case 'EXEC':
- case 'WATCH':
- case 'UNWATCH':
- case 'DISCARD':
- case 'MONITOR':
- throw new NotSupportedException("Command '$commandID' is not allowed by Webdis.");
- default:
- return $commandID;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function writeRequest(CommandInterface $command)
- {
- $this->throwNotSupportedException(__FUNCTION__);
- }
-
- /**
- * {@inheritdoc}
- */
- public function readResponse(CommandInterface $command)
- {
- $this->throwNotSupportedException(__FUNCTION__);
- }
-
- /**
- * {@inheritdoc}
- */
- public function executeCommand(CommandInterface $command)
- {
- $resource = $this->resource;
- $commandId = $this->getCommandId($command);
-
- if ($arguments = $command->getArguments()) {
- $arguments = implode('/', array_map('urlencode', $arguments));
- $serializedCommand = "$commandId/$arguments.raw";
- } else {
- $serializedCommand = "$commandId.raw";
- }
-
- curl_setopt($resource, CURLOPT_POSTFIELDS, $serializedCommand);
-
- if (curl_exec($resource) === false) {
- $error = trim(curl_error($resource));
- $errno = curl_errno($resource);
-
- throw new ConnectionException($this, "$error{$this->getParameters()}]", $errno);
- }
-
- if (phpiredis_reader_get_state($this->reader) !== PHPIREDIS_READER_STATE_COMPLETE) {
- throw new ProtocolException($this, phpiredis_reader_get_error($this->reader));
- }
-
- return phpiredis_reader_get_reply($this->reader);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getResource()
- {
- return $this->resource;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getParameters()
- {
- return $this->parameters;
- }
-
- /**
- * {@inheritdoc}
- */
- public function addConnectCommand(CommandInterface $command)
- {
- $this->throwNotSupportedException(__FUNCTION__);
- }
-
- /**
- * {@inheritdoc}
- */
- public function read()
- {
- $this->throwNotSupportedException(__FUNCTION__);
- }
-
- /**
- * {@inheritdoc}
- */
- public function __toString()
- {
- return "{$this->parameters->host}:{$this->parameters->port}";
- }
-
- /**
- * {@inheritdoc}
- */
- public function __sleep()
- {
- return ['parameters'];
- }
-
- /**
- * {@inheritdoc}
- */
- public function __wakeup()
- {
- $this->assertExtensions();
-
- $this->resource = $this->createCurl();
- $this->reader = $this->createReader();
- }
-}
diff --git a/tests/Predis/Cluster/Hash/PhpiredisCRC16Test.php b/tests/Predis/Cluster/Hash/PhpiredisCRC16Test.php
deleted file mode 100644
index b274887e..00000000
--- a/tests/Predis/Cluster/Hash/PhpiredisCRC16Test.php
+++ /dev/null
@@ -1,42 +0,0 @@
-assertSame(58359, $crc16->hash('key:000'));
- $this->assertSame(62422, $crc16->hash('key:001'));
- $this->assertSame(50101, $crc16->hash('key:002'));
- $this->assertSame(54164, $crc16->hash('key:003'));
- $this->assertSame(41843, $crc16->hash('key:004'));
- $this->assertSame(45906, $crc16->hash('key:005'));
- $this->assertSame(33585, $crc16->hash('key:006'));
- $this->assertSame(37648, $crc16->hash('key:007'));
- $this->assertSame(25343, $crc16->hash('key:008'));
- $this->assertSame(29406, $crc16->hash('key:009'));
- }
-}
diff --git a/tests/Predis/Configuration/Option/CRC16Test.php b/tests/Predis/Configuration/Option/CRC16Test.php
index 54173d92..41d80318 100644
--- a/tests/Predis/Configuration/Option/CRC16Test.php
+++ b/tests/Predis/Configuration/Option/CRC16Test.php
@@ -30,11 +30,7 @@ class CRC16Test extends PredisTestCase
$this->assertInstanceOf('Predis\Cluster\Hash\HashGeneratorInterface', $hashGenerator);
- if (function_exists('phpiredis_utils_crc16')) {
- $this->assertInstanceOf('Predis\Cluster\Hash\PhpiredisCRC16', $hashGenerator);
- } else {
- $this->assertInstanceOf('Predis\Cluster\Hash\CRC16', $hashGenerator);
- }
+ $this->assertInstanceOf('Predis\Cluster\Hash\CRC16', $hashGenerator);
}
/**
@@ -113,29 +109,13 @@ class CRC16Test extends PredisTestCase
$this->assertInstanceOf('Predis\Cluster\Hash\CRC16', $option->filter($options, 'predis'));
}
- /**
- * @group disconnected
- * @group ext-phpiredis
- * @requires extension phpiredis
- * @requires function phpiredis_utils_crc16
- */
- public function testAcceptsShortNameStringPhpiredis(): void
- {
- $option = new CRC16();
-
- /** @var OptionsInterface */
- $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
-
- $this->assertInstanceOf('Predis\Cluster\Hash\PhpiredisCRC16', $option->filter($options, 'phpiredis'));
- }
-
/**
* @group disconnected
*/
public function testThrowsExceptionOnInvalidShortNameString(): void
{
$this->expectException('InvalidArgumentException');
- $this->expectExceptionMessage('String value for the crc16 option must be either `predis` or `phpiredis`');
+ $this->expectExceptionMessage('String value for the crc16 option must be either `predis`');
$option = new CRC16();
diff --git a/tests/Predis/Configuration/Option/ConnectionsTest.php b/tests/Predis/Configuration/Option/ConnectionsTest.php
index 346049b0..1fb0a391 100644
--- a/tests/Predis/Configuration/Option/ConnectionsTest.php
+++ b/tests/Predis/Configuration/Option/ConnectionsTest.php
@@ -229,9 +229,6 @@ class ConnectionsTest extends PredisTestCase
public function provideSupportedStringValuesForOption()
{
return [
- ['phpiredis-stream', 'Predis\Connection\PhpiredisStreamConnection'],
- ['phpiredis-socket', 'Predis\Connection\PhpiredisSocketConnection'],
- ['phpiredis', 'Predis\Connection\PhpiredisStreamConnection'],
['relay', \Predis\Connection\RelayConnection::class],
];
}
diff --git a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php
deleted file mode 100644
index 8c4dd117..00000000
--- a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php
+++ /dev/null
@@ -1,120 +0,0 @@
-expectException('InvalidArgumentException');
- $this->expectExceptionMessage("Invalid scheme: 'tls'");
-
- $connection = $this->createConnectionWithParams(['scheme' => 'tls']);
-
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- /**
- * @group disconnected
- */
- public function testSupportsSchemeRediss(): void
- {
- $this->expectException('InvalidArgumentException');
- $this->expectExceptionMessage("Invalid scheme: 'rediss'");
-
- $connection = $this->createConnectionWithParams(['scheme' => 'rediss']);
-
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- /**
- * @group disconnected
- */
- public function testThrowsExceptionOnInitializationCommandFailure(): void
- {
- $this->expectException('Predis\Connection\ConnectionException');
- $this->expectExceptionMessage('`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]');
-
- $cmdSelect = RawCommand::create('SELECT', '1000');
-
- /** @var NodeConnectionInterface|MockObject */
- $connection = $this
- ->getMockBuilder($this->getConnectionClass())
- ->onlyMethods(['executeCommand', 'createResource'])
- ->setConstructorArgs([new Parameters()])
- ->getMock();
- $connection
- ->method('executeCommand')
- ->with($cmdSelect)
- ->willReturn(
- new ErrorResponse('ERR invalid DB index')
- );
-
- $connection->method('createResource');
-
- $connection->addConnectCommand($cmdSelect);
- $connection->connect();
- }
-
- // ******************************************************************** //
- // ---- INTEGRATION TESTS --------------------------------------------- //
- // ******************************************************************** //
-
- /**
- * @group connected
- */
- public function testThrowsExceptionOnUnresolvableHostname(): void
- {
- $this->expectException('Predis\Connection\ConnectionException');
- $this->expectExceptionMessage("Cannot resolve the address of 'bogus.tld'");
-
- $connection = $this->createConnectionWithParams(['host' => 'bogus.tld']);
- $connection->connect();
- }
-
- /**
- * @medium
- * @group connected
- */
- public function testThrowsExceptionOnProtocolDesynchronizationErrors(): void
- {
- $this->expectException('Predis\Protocol\ProtocolException');
-
- $connection = $this->createConnection();
- $socket = $connection->getResource();
-
- $connection->writeRequest($this->getCommandFactory()->create('ping'));
- socket_read($socket, 1);
-
- $connection->read();
- }
-}
diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php
deleted file mode 100644
index 83c5d2a5..00000000
--- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-expectException('InvalidArgumentException');
- $this->expectExceptionMessage('SSL encryption is not supported by this connection backend');
-
- $connection = $this->createConnectionWithParams(['scheme' => 'tls']);
-
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- /**
- * @group disconnected
- */
- public function testSupportsSchemeRediss(): void
- {
- $this->expectException('InvalidArgumentException');
- $this->expectExceptionMessage('SSL encryption is not supported by this connection backend');
-
- $connection = $this->createConnectionWithParams(['scheme' => 'rediss']);
-
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- /**
- * @group disconnected
- */
- public function testThrowsExceptionOnInitializationCommandFailure(): void
- {
- $this->expectException('Predis\Connection\ConnectionException');
- $this->expectExceptionMessage('`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]');
-
- $cmdSelect = RawCommand::create('SELECT', '1000');
-
- /** @var NodeConnectionInterface|MockObject */
- $connection = $this
- ->getMockBuilder($this->getConnectionClass())
- ->onlyMethods(['executeCommand', 'createResource'])
- ->setConstructorArgs([new Parameters()])
- ->getMock();
- $connection
- ->method('executeCommand')
- ->with($cmdSelect)
- ->willReturn(
- new ErrorResponse('ERR invalid DB index')
- );
-
- $connection->method('createResource');
-
- $connection->addConnectCommand($cmdSelect);
- $connection->connect();
- }
-
- // ******************************************************************** //
- // ---- INTEGRATION TESTS --------------------------------------------- //
- // ******************************************************************** //
-
- /**
- * @group connected
- * @group slow
- * @requires PHP 5.4
- */
- public function testThrowsExceptionOnReadWriteTimeout(): void
- {
- $this->expectException('Predis\Connection\ConnectionException');
-
- $connection = $this->createConnectionWithParams([
- 'read_write_timeout' => 0.5,
- ], true);
-
- $connection->executeCommand(
- $this->getCommandFactory()->create('brpop', ['foo', 3])
- );
- }
-
- /**
- * @medium
- * @group connected
- */
- public function testThrowsExceptionOnProtocolDesynchronizationErrors(): void
- {
- $this->expectException('Predis\Protocol\ProtocolException');
-
- $connection = $this->createConnection();
- $stream = $connection->getResource();
-
- $connection->writeRequest($this->getCommandFactory()->create('ping'));
- stream_socket_recvfrom($stream, 1);
-
- $connection->read();
- }
-
- /**
- * @group connected
- * @requires PHP 5.4
- */
- public function testPersistentParameterWithFalseLikeValues(): void
- {
- $connection1 = $this->createConnectionWithParams(['persistent' => 0]);
- $this->assertNonPersistentConnection($connection1);
-
- $connection2 = $this->createConnectionWithParams(['persistent' => false]);
- $this->assertNonPersistentConnection($connection2);
-
- $connection3 = $this->createConnectionWithParams(['persistent' => '0']);
- $this->assertNonPersistentConnection($connection3);
-
- $connection4 = $this->createConnectionWithParams(['persistent' => 'false']);
- $this->assertNonPersistentConnection($connection4);
- }
-
- /**
- * @group connected
- * @requires PHP 5.4
- */
- public function testPersistentParameterWithTrueLikeValues(): void
- {
- $connection1 = $this->createConnectionWithParams(['persistent' => 1]);
- $this->assertPersistentConnection($connection1);
-
- $connection2 = $this->createConnectionWithParams(['persistent' => true]);
- $this->assertPersistentConnection($connection2);
-
- $connection3 = $this->createConnectionWithParams(['persistent' => '1']);
- $this->assertPersistentConnection($connection3);
-
- $connection4 = $this->createConnectionWithParams(['persistent' => 'true']);
- $this->assertPersistentConnection($connection4);
-
- $connection1->disconnect();
- }
-
- /**
- * @group connected
- * @requires PHP 5.4
- */
- public function testPersistentConnectionsToSameNodeShareResource(): void
- {
- $connection1 = $this->createConnectionWithParams(['persistent' => true]);
- $connection2 = $this->createConnectionWithParams(['persistent' => true]);
-
- $this->assertPersistentConnection($connection1);
- $this->assertPersistentConnection($connection2);
-
- $this->assertSame($connection1->getResource(), $connection2->getResource());
-
- $connection1->disconnect();
- }
-
- /**
- * @group connected
- * @requires PHP 5.4
- */
- public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID(): void
- {
- $connection1 = $this->createConnectionWithParams(['persistent' => 'conn1']);
- $connection2 = $this->createConnectionWithParams(['persistent' => 'conn2']);
-
- $this->assertPersistentConnection($connection1);
- $this->assertPersistentConnection($connection2);
-
- $this->assertNotSame($connection1->getResource(), $connection2->getResource());
- }
-
- /**
- * @group connected
- */
- public function testTcpNodelayParameterSetsContextFlagWhenTrue()
- {
- $connection = $this->createConnectionWithParams(['tcp_nodelay' => true]);
- $options = stream_context_get_options($connection->getResource());
-
- $this->assertIsArray($options);
- $this->assertArrayHasKey('socket', $options);
- $this->assertArrayHasKey('tcp_nodelay', $options['socket']);
- $this->assertTrue($options['socket']['tcp_nodelay']);
- }
-
- /**
- * @group connected
- */
- public function testTcpNodelayParameterDoesNotSetContextFlagWhenFalse()
- {
- $connection = $this->createConnectionWithParams(['tcp_nodelay' => false]);
- $options = stream_context_get_options($connection->getResource());
-
- $this->assertIsArray($options);
- $this->assertArrayHasKey('socket', $options);
- $this->assertArrayHasKey('tcp_nodelay', $options['socket']);
- $this->assertFalse($options['socket']['tcp_nodelay']);
- }
-
- /**
- * @group connected
- */
- public function testTcpDelayContextFlagIsNotSetByDefault()
- {
- $connection = $this->createConnectionWithParams([]);
- $options = stream_context_get_options($connection->getResource());
-
- $this->assertIsArray($options);
- $this->assertArrayHasKey('socket', $options);
- $this->assertArrayHasKey('tcp_nodelay', $options['socket']);
- $this->assertFalse($options['socket']['tcp_nodelay']);
- }
-}
diff --git a/tests/Predis/Connection/WebdisConnectionTest.php b/tests/Predis/Connection/WebdisConnectionTest.php
deleted file mode 100644
index e0d6797e..00000000
--- a/tests/Predis/Connection/WebdisConnectionTest.php
+++ /dev/null
@@ -1,227 +0,0 @@
-createConnection();
-
- $this->assertTrue($connection->isConnected());
- }
-
- /**
- * @group disconnected
- */
- public function testSupportsSchemeUnix(): void
- {
- $connection = $this->createConnectionWithParams(['scheme' => 'http']);
-
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- /**
- * @group disconnected
- */
- public function testThrowsExceptionOnInvalidScheme(): void
- {
- $this->expectException('InvalidArgumentException');
- $this->expectExceptionMessage("Invalid scheme: 'tcp'");
-
- $connection = $this->createConnectionWithParams(['scheme' => 'tcp']);
- }
-
- /**
- * @group disconnected
- */
- public function testWritingCommandsIsNotSupported(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::writeRequest() is not supported");
-
- $connection = $this->createConnection();
- $connection->writeRequest($this->getCommandFactory()->create('ping'));
- }
-
- /**
- * @group disconnected
- */
- public function testReadingResponsesIsNotSupported(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::readResponse() is not supported");
-
- $connection = $this->createConnection();
- $connection->readResponse($this->getCommandFactory()->create('ping'));
- }
-
- /**
- * @group disconnected
- */
- public function testReadingFromConnectionIsNotSupported(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::read() is not supported");
-
- $connection = $this->createConnection();
- $connection->read();
- }
-
- /**
- * @group disconnected
- */
- public function testAddingConnectCommandsIsNotSupported(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported");
-
- $connection = $this->createConnection();
- $connection->addConnectCommand($this->getCommandFactory()->create('ping'));
- }
-
- /**
- * @group disconnected
- */
- public function testRejectCommandSelect(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("Command 'SELECT' is not allowed by Webdis");
-
- $connection = $this->createConnection();
- $connection->executeCommand($this->getCommandFactory()->create('select', [0]));
- }
-
- /**
- * @group disconnected
- */
- public function testRejectCommandAuth(): void
- {
- $this->expectException('Predis\NotSupportedException');
- $this->expectExceptionMessage("Command 'AUTH' is not allowed by Webdis");
-
- $connection = $this->createConnection();
- $connection->executeCommand($this->getCommandFactory()->create('auth', ['foobar']));
- }
-
- /**
- * @group disconnected
- */
- public function testCanBeSerialized(): void
- {
- $parameters = $this->getParameters([
- 'alias' => 'redis',
- 'read_write_timeout' => 10,
- ]);
-
- $connection = $this->createConnectionWithParams($parameters);
-
- $unserialized = unserialize(serialize($connection));
-
- $this->assertInstanceOf('Predis\Connection\WebdisConnection', $unserialized);
- $this->assertEquals($parameters, $unserialized->getParameters());
- }
-
- // ******************************************************************** //
- // ---- INTEGRATION TESTS --------------------------------------------- //
- // ******************************************************************** //
-
- /**
- * @group connected
- */
- public function testExecutesMultipleCommandsOnServer(): void
- {
- $commands = $this->getCommandFactory();
-
- $cmdPing = $commands->create('ping');
- $cmdEcho = $commands->create('echo', ['echoed']);
- $cmdGet = $commands->create('get', ['foobar']);
- $cmdRpush = $commands->create('rpush', ['metavars', 'foo', 'hoge', 'lol']);
- $cmdLrange = $commands->create('lrange', ['metavars', 0, -1]);
-
- $connection = $this->createConnection(true);
-
- $this->assertEquals('PONG', $connection->executeCommand($cmdPing));
- $this->assertSame('echoed', $connection->executeCommand($cmdEcho));
- $this->assertNull($connection->executeCommand($cmdGet));
- $this->assertSame(3, $connection->executeCommand($cmdRpush));
- $this->assertSame(['foo', 'hoge', 'lol'], $connection->executeCommand($cmdLrange));
- }
-
- /**
- * @medium
- * @group disconnected
- * @group slow
- */
- public function testThrowExceptionWhenUnableToConnect(): void
- {
- $this->expectException('Predis\Connection\ConnectionException');
-
- $connection = $this->createConnectionWithParams(['host' => '169.254.10.10']);
- $connection->executeCommand($this->getCommandFactory()->create('ping'));
- }
-
- // ******************************************************************** //
- // ---- HELPER METHODS ------------------------------------------------ //
- // ******************************************************************** //
-
- /**
- * Returns a named array with the default connection parameters and their values.
- *
- * @return array Default connection parameters
- */
- protected function getDefaultParametersArray(): array
- {
- return [
- 'scheme' => 'http',
- 'host' => constant('WEBDIS_SERVER_HOST'),
- 'port' => constant('WEBDIS_SERVER_PORT'),
- ];
- }
-
- /**
- * {@inheritdoc}
- */
- protected function createConnection(): NodeConnectionInterface
- {
- return $this->createConnectionWithParams([]);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function createConnectionWithParams($parameters): NodeConnectionInterface
- {
- if (!$parameters instanceof ParametersInterface) {
- $parameters = $this->getParameters($parameters);
- }
-
- $connection = new WebdisConnection($parameters);
- $connection->executeCommand($this->getCommandFactory()->create('flushdb'));
-
- return $connection;
- }
-}