43 Commits

Author SHA1 Message Date
Till Krüss 581c5659bd update year in headers 2026-02-23 11:48:06 -08:00
Vladyslav Vildanov 7c7cf90152 Improve connection handshake by pipelining commands (#1622)
* Improve connection handshake by pipelining commands

* Added exceptions handling for Redis < 6.0

* Updated CHANGELOG.md
2026-01-08 13:56:55 +02:00
Vladyslav Vildanov 980326d5d8 Added retry support (#1616)
* Initial work on retries

* Added retry class and test coverage

* Added support for standalone and cluster

* Make TimeoutException instance of CommunicationException

* Added pipeline, trasnaction, replication support

* Fixed broken test

* Marked test as relay-incompatible

* Marked test as relay-incompatible

* Fixed analysis errors, added missing tests

* Codestyle fixes

* Fixed test

* Update README.md

* Update README.md

* Update README.md

* Updated README.md

* Refactor retry on read and write

* Added check for timeout value

* Updated README.md

* Fixed README.md

* Codestyle changes

* Added missing coverage

* Added missing test coverage

* Removed comments

* Added retry support for Relay connection (#1620)

* Added integration test case with mocked retry

* Changed client initialisation in tests

* Marked test as relay-incompatible

---------

Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
2025-12-23 10:40:46 +02:00
Vladyslav Vildanov 06c904af37 fix(auth): Adds default user if only password used for authentication (#1535) 2025-05-13 09:01:21 -07:00
Pavlo Yatsukhnenko 9b1c6d2c8f Update tests against Relay (#1537) 2025-05-12 09:00:40 -07:00
vladvildanov 8bc9a4d432 Merge branch 'v2.x' of github.com:predis/predis into vv-main-2.x-sync 2025-03-31 11:36:25 +03:00
Till Krüss ba66e22c92 bump year to 2025 2025-01-22 09:24:26 -08:00
Till Krüss 7631d317fd update year 2024-11-21 11:37:10 -08:00
Vladyslav Vildanov c83ee6a809 Implemented PSR-7 compatible stream abstraction (#1450)
* Implemented PSR-7 compatible stream abstraction

* Added missing coverage, fixing static analysis issues

* Fixed return type

* Added missing throws statements

* Added ignore lines
2024-04-10 12:52:53 +03:00
Till Krüss 946c4b7bd7 [v2.x] Relay support (#1263) 2023-05-09 10:39:00 -07:00
Till Krüss 82791e55e1 format tests 2023-01-17 15:08:18 -08:00
Till Krüss af2e5cc553 order imports 2023-01-17 15:08:18 -08:00
Till Krüss cc40219268 use short array syntax 2023-01-17 15:08:18 -08:00
Till Krüss c9babb1984 update copyright comments 2023-01-17 13:41:35 -08:00
Daniele Alessandri b1ea4374d4 [tests] Fix the very few remaining warnings emitted by test suite.
Basically assertMatchesRegularExpression() replaces assertRegExp() which
has been deprecated since PHPUnit 9.1 and will be removed in PHPUnit 10,
unfortunately we still depend on PHPUnit 8.4 to support PHP 7.2 and this
version does not have assertMatchesRegularExpression() so we implemented
it in our base testcase class with a fallback to the old assertRegExp()
when tests are executed on older versions of PHPUnit.
2020-09-04 21:00:46 +02:00
Daniele Alessandri c6f2ce4b83 [tests] Replace generic MockObject::will() with specialized methods. 2020-09-01 14:03:19 +02:00
Daniele Alessandri 36c9bb047e [tests] Start improving test suite.
- Make use of more typehints for function parameters
- Make use of typehints for function return values
- Use @var where needed to give proper hints to IDEs and avoid warnings
- Replace MockObject::setMethods() with addMethods() and onlyMethods()
- Rewording of some phpdocs
2020-09-01 13:58:14 +02:00
Daniele Alessandri cc2a7657db Rework Predis\Command\FactoryInterface and related classes.
We have renamed most methods to drop the "command" suffix as it is quite
redundant. Due to this change and thanks to variadic methods introduced
with PHP 5.6 we took the opportunity to replace both "supportsCommand()"
and "supportsCommands()" with a single new method "supports()".

Added more stringent typehints for method arguments and typehints for
return values now that we do not need to support anything below PHP 7.2.
Also moved from using array() to [] in source code of class involved.
2020-08-28 14:23:12 +02:00
Daniele Alessandri c26909699b Merge remote-tracking branch 'github/pr/639' into main 2020-08-18 16:03:10 +02:00
Raza Mehdi 5edf443141 Fix tests. 2020-08-16 01:59:41 +05:00
Daniele Alessandri eb1e686ff9 [tests] Change indentation of mock method expectations. 2016-06-10 11:08:26 +02:00
Daniele Alessandri 62b421f20e Switch from server profiles to commands factory.
This change reduces some unnecessary complexity in the library, Redis
commands do not change much after all. Developers can still implement
their own commands factory, inject new commands or override existing
ones. The "profile" client options has been renamed to "commands" and
it accepts instances of Predis\Command\FactoryInterface.

The test suite checks at runtime the version of the running instance
of Redis for integration tests to adapt itself automatically.
2016-06-04 15:36:21 +02:00
Daniele Alessandri f6bf2b5977 [tests] Troubles with HHVM <= 3.6.6 and float timeouts.
HHVM is still being used by Travis CI but this bug makes the build to
take 14 minutes to complete, which is unacceptable.
2016-05-30 17:09:02 +02:00
Daniele Alessandri e61cb4e4f2 [tests] Fix wrong @group annotation 2016-05-09 17:49:12 +02:00
Daniele Alessandri a0487ec5f4 Prevent failures serializing commands with "holes" in arguments array.
This could be triggered when passing an array with "holes" to variadic commands.
Connection classes based on the protocol serialized exposed by phpiredis were
not affected by this bug.

Fixes #316.
2016-05-08 18:43:50 +02:00
Daniele Alessandri a7ee80702c Implement full support for IPv6.
Using IPv6 with Predis was basically impossible due to various inconsistencies
and bugs through the library, now it is supported by all the connection classes.

Following the standard for IPv6 literal addresses in URI strings, the IP literal
must be enclosed within square brackets when passing the parameters as a string:

  $parameters = 'tcp://[2001:db8:0:f101::1]:6379';

See https://tools.ietf.org/html/rfc3986#section-3.2.2 for further details.

This commit also fixes #239 making redis-cluster usable with nodes using IPv6.
2015-07-29 23:01:55 +02:00
Daniele Alessandri ebb72377bb Implement TLS/SSL-encrypted connections.
This is handy for accessing remote Redis instances over a secure SSL connection
which is currently a popular option or even requirement with many cloud hosting
environments.

In order to configure the client to use an SSL-encrypted connection the scheme
in the connection parameters must be either "tsl" or "rediss" and a set of SSL
options (see http://php.net/manual/en/context.ssl.php) must be provided via the
"ssl" parameter as a named array.

The following example (which does not necessarily represent an example of good
practices!) illustrates how to set the "ssl" parameter using a named array and
the equivalent URI string:

  // Parameters as named array
  $parameters = [
    'scheme' => 'tls',
    'host'   => '127.0.0.1',
    'ssl'    => [
        'cafile'            => '/home/adaniele/redis.pem',
        'verify_peer_name'  => false,
    ],
  ];

  // Parameters as URI string
  $parameters = 'tls://127.0.0.1?ssl[cafile]=redis.pem&ssl[verify_peer_name]=1';

Support for SSL is currently limited to the Predis\Connection\StreamConnection
backend but we intend to investigate if it is possible to extend this feature
to Predis\Connection\PhpiredisStreamConnection in the future.

Be aware that using encrypted connections may lead to a performance degradation
especially in the connect() operation due to the overhead of the TLS handshake.
Unfortunately there is no real way to reuse SSL sessions from userland, aside
from enabling persistent connections, but this will work only on PHP >= 7.0.0
because previous versions of PHP do not provide enough info about a stream from
get_stream_meta_data().

NOTE: Redis does not have built-in support for SSL-encrypted connections, but if
you want to expose it to public networks you may want to rely on "stunnel".
2015-07-27 19:16:20 +02:00
Daniele Alessandri abf2ce0bd1 [tests] Exlude persistent connections tests under PHP 5.3.
The get_resource_type() function does not differentiate between normal streams
and persistent streams, so we cannot really test this case.
2015-07-25 21:52:55 +02:00
Daniele Alessandri c7cae66a97 [tests] Improve code-reuse in tests for the Predis\Connection namespace. 2015-07-25 21:32:36 +02:00
Daniele Alessandri 1c8eb7ff6b [tests] Share common test among connection classes. 2015-07-25 19:13:01 +02:00
Daniele Alessandri 8277afc7a8 Use "persistent" with non-bool strings to open different persistent connections.
stream_socket_client() has the undocumented ability to open different persistent
streams by providing a path in the $address string. Previously we supported this
behaviour with a combination of "persistent" and "path" (see #139) but this can
be confusing, especially now that we support the redis:// scheme which uses the
path part of an URI string to specify a database number.

After this change, instead of using an URI string such as:

  $parameters = 'tcp://127.0.0.1/first?persistent=1&database=5';

You should use the following ones:

  $parameters = 'tcp://127.0.0.1?persistent=first&database=5';
  $parameters = 'redis://127.0.0.1/5?persistent=first';

Avoiding "path" makes even more sense when using array connection parameters:

  $parameters = [
    'host'       => '127.0.0.1',
    'database'   => 5,
    'persistent' => 'first',
  ]

This feature is not supported when using UNIX domain sockets because the path
trick of stream_socket_client() does not play well with the actual path of the
socket file. The client will throw an InvalidArgumentException exception to
notify the user.

NOTE: unfortunately we have to disable the tests for persistent connections when
running under HHVM due to a bug in their implementation of get_resource_type()
preventing us to recognize a persistent stream from userland code.
2015-07-25 18:34:51 +02:00
Daniele Alessandri 8dd9893a2f Run php-cs-fixer with new configuration. 2015-07-24 23:17:02 +02:00
Daniele Alessandri 45e351be79 [phpdoc] Fix formatting of phpdoc headers. 2014-07-27 23:59:37 +02:00
Daniele Alessandri dbfc1a74ba More random fixes after inspection. 2014-07-27 23:06:17 +02:00
Daniele Alessandri aa5c893d5a [phpdoc] Fix undefined namespaces. 2014-07-27 21:57:40 +02:00
Daniele Alessandri 7ba465048f Do not throw exception when connection has been already established.
The base abstract connection class now returns a bool to indicate when
the actual connect() operation has been performed on the underlying
resource. This return value is not part of the interface so extending
classes can decide to not return any value.
2013-12-21 12:32:15 +01:00
Daniele Alessandri 2a6409590c Run php-cs against test suite. 2013-12-17 12:55:56 +01:00
Daniele Alessandri 0f34f41ccf Fix and reword some exception messages. 2013-12-16 15:13:18 +01:00
Daniele Alessandri 6ceebbfbec Rename Predis\Connection\SingleConnectionInterface::pushInitCommand().
The new name is more explicit as it makes obvious that the commands
added with it will be executed upon connect().
2013-12-15 11:25:38 +01:00
Daniele Alessandri 8744285cb3 Ignoring the plural form of "reply" for renames is dumb...
[ci skip]
2013-12-10 18:08:14 +01:00
Daniele Alessandri 373d30b070 Use Predis\Response\Status to identify all kinds of status responses.
Status response objects are needed mostly to make it possible from the
client perspective to differentiate a status response with the payload
"OK" from a normale bulk reply containing "OK".

The biggest change is for commands returning +OK responses: these were
previously translated to TRUE (bool value), but they are now returned
as instances of Predis\Response\Status. Just to illustrate an example
of the possibilities with this change we will use SET since it is the
most widely used command returning +OK:

  $response = $client->set('foo', 'bar');

  echo $response;         // 'OK'
  $response == 'OK';      // TRUE
  isset($response->ok);   // TRUE
  $response == true;      // TRUE
  $response === true;     // FALSE
  $response instanceof Predis\Response\ObjectInterface;     // TRUE
  $response instanceof Predis\Response\Status;              // TRUE

For those checking responses returned by commands such as SET or PONG,
the breaking change basically lies in the usage of strict comparison:
doing $response === true will now evaluate to FALSE instead of TRUE.

By default Predis caches common status responses such as OK or QUEUED
to lower the memory usage when using pipelines or transactions.
2013-12-07 15:15:23 +01:00
Daniele Alessandri 4bf0ee4c6a Rename ConnectionInterface::writeCommand() to writeRequest().
This name is more consistent with its counterpart, readResponse().
2013-12-02 11:08:14 +01:00
Daniele Alessandri d2c001812f [tests] Rename test case classes. 2013-12-01 15:11:09 +01:00