Commit Graph

137 Commits

Author SHA1 Message Date
Daniele Alessandri 7cf9cfc496 Update phpdocs.
[ci skip]
2013-12-19 11:20:27 +01:00
Daniele Alessandri 02e43143d3 Run php-cs against codebase. 2013-12-17 12:53:36 +01:00
Daniele Alessandri 0f34f41ccf Fix and reword some exception messages. 2013-12-16 15:13:18 +01:00
Daniele Alessandri 7e89719ceb Revert usage of "short" namespaces in use directives.
We started using partially-qualified names as an experiment but we are
reverting to using fully-qualified names + aliases in use directives.
2013-12-15 17:00:45 +01:00
Daniele Alessandri 0779c1c24a Trim some more "use" directives in Predis\Client. 2013-12-15 14:01:05 +01:00
Daniele Alessandri 58c5029574 Rename Predis\Connection\AggregatedConnectionInterface. 2013-12-15 12:38:21 +01:00
Daniele Alessandri c40ad5dd47 Rename Predis\Connection\ConnectionParameters. 2013-12-15 10:22:23 +01:00
Daniele Alessandri cbf015164c Rename Predis\Client::raw() to Predis\Client::executeRaw().
This is more consistent with Predis\Client::executeRaw() and its more
explicit since simply "raw" as a method name was a bit too vague even
despite being nicely short.
2013-12-14 20:37:28 +01:00
Daniele Alessandri 59b5658cf5 Big batch of phpdoc improvements and minor code styling fixes. 2013-12-10 19:21:52 +01:00
Daniele Alessandri 427309db69 Apply code styling fixes.
There is actually no need for such indentations.
2013-12-07 15:41:45 +01:00
Daniele Alessandri ee45de4f0e Rename base response interface to Predis\Response\ResponseInterface. 2013-12-07 15:22:42 +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 583b924085 Add the ability for the client to send raw commands to Redis.
When sending raw commands their arguments are not filtered, responses
are not parsed and key prefixes are not applied. The client also does
not throw any exception on Redis errors regardless of its settings.

The first parameter takes the raw arguments of the command (included
its identifier) as defined by the Redis documentation while the second
optional parameter is always populated by reference to indicate when
Redis actually returned an error response.

  $client->raw(['PING']);                // "PONG"
  $client->raw(['SET','foo','bar']);     // "OK"
  $client->raw(['GET','foo'], $err);     // "bar", $err=FALSE
  $client->raw(['LPUSH','foo',1], $err); // "WRONGTYPE...", $err=TRUE

Internally, this method creates instances of Predis\Command\RawCommand
that get passed to the underlying connection instance for execution as
if they were usual commands defined by Predis.

Raw commands work in both cluster and replication scenarios since they
are recognized by their command ID, but key prefixing is not supported
since it is done by the profile instance when instantiating commands.
2013-12-01 13:42:03 +01:00
Daniele Alessandri 09895f27bf Rename command class for scripting to Predis\Command\ScriptCommand.
We also changed our wording to indentify this kind of abstraction so
instead of using "scripted commands" (kind of broken English) we now
use "scriptable commands".
2013-11-30 12:43:21 +01:00
Daniele Alessandri 374101cfc3 Apply minor change. 2013-11-22 12:17:57 +01:00
Daniele Alessandri 2a5483df90 Reorganize the Predis\Profile namespace.
The profile factory code has been extrapolated into a the new class
Predis\Profile\Factory (final and with only static methods).
2013-11-22 12:01:29 +01:00
Daniele Alessandri 3d499e82a3 Add some supported options to Predis\Client::pipeline().
Only two options available for now, used to specify which kind of
pipeline object the client should use or return:

  - "atomic": returns a pipeline wrapped in a MULTI / EXEC transaction
    (class: Predis\Pipeline\Atomic).
  - "fire-and-forget": returns a pipeline that does not read back
    responses from the server (class: Predis\Pipeline\FireAndForget).

We might add more options in the future.
2013-11-16 21:54:17 +01:00
Daniele Alessandri 8068c87e47 Rewrite a good chunk of the classes in the Predis\Pipeline namespace.
First of all we completely removed the concept of pipeline executors.
Now pipelines can be easily customized by extending our default class
Predis\Pipeline\Pipeline.

Tests coverage for the Predis\Pipeline namespace is decent but can be
definitely improved while test cases can be beautified.
2013-11-16 21:23:49 +01:00
Daniele Alessandri c6f51e82bf Rename "Array" type-hint to to "array". 2013-11-16 17:01:58 +01:00
Daniele Alessandri aaac082324 Rename classes in Predis\Transaction. 2013-11-16 16:34:34 +01:00
Daniele Alessandri 9d2cb975eb Rename classes in Predis\Monitor namespace. 2013-11-16 15:42:56 +01:00
Daniele Alessandri c3a58dffdf Rename classes in the Predis\PubSub namespace. 2013-11-16 15:27:58 +01:00
Daniele Alessandri b71c798f9b Rename classes in Predis\Response and Predis\Response\Iterator.
This change aims to make class names shorter with less redundant fully
qualified names.

Merge!
2013-11-16 14:01:11 +01:00
Daniele Alessandri a8edc02eb6 Create the Predis\Response namespace.
All of the response interface, classes and exceptions have been moved
into this namespace.
2013-11-16 11:59:33 +01:00
Daniele Alessandri b0f955b437 Fix phpdocs.
[ci skip]
2013-11-12 19:49:55 +01:00
Daniele Alessandri a1c7889584 Add option "aggregate" to customize multiple connections aggregation.
This option must return a callable object that is used to override how
the client aggregates connections when passing an array of parameters
to its constructor.

When specified, this option overrides both "cluster" and "replication"
as it allows to make use of your own code to aggregate multiple nodes.

This is, for example, how you can mimic the standard initialization of
a cluster that relies on client-side sharding:

  $parameters = ['tcp://127.0.0.1:6380', 'tcp://127.0.0.1:6381'];

  $options = [
    'aggregate' => function () {
      return function ($parameters, $options) {
          $connection = new Predis\Connection\PredisCluster();
          $options->connections->aggregate($connection, $parameters);

          return $connection;
      };
    },
  ];

  $client = new Predis\Client($parameters, $options);

When invoked by the client, the specified callable must always return
a Predis\Connection\ConnectionInterface instance or the client will
throw an UnexpectedValueException.
2013-11-12 12:31:45 +01:00
Daniele Alessandri acd29ec076 Slightly change interface for connection factories. 2013-11-11 18:24:20 +01:00
Daniele Alessandri 3c6389f4dd Rework how connection parameters are handled.
These changes do not affect the actual functionalities of the client,
but make the code more explicit and less error-prone.
2013-11-11 18:17:09 +01:00
Daniele Alessandri 1d53f8a988 Minor code styling changes. 2013-11-11 15:59:21 +01:00
Daniele Alessandri dd679661dd Address #133 by reusing our own methods.
The main reason behind that code duplication was performance related
as we tried to reduce method calls when possible, even at the cost of
falling into the realm of early optimizations. Apparently we just lose
~400 req/sec on a 21000 req/sec basis ("SET foo bar") using PHP 5.5.3
(packaged by Ubuntu 13.10) on an Intel Q6600, so we will most likely
stick with this change for the sake of best practices.
2013-11-11 15:49:16 +01:00
Daniele Alessandri 31e08f0d5d Tweak phpdocs. 2013-11-11 12:29:43 +01:00
Daniele Alessandri cdb91284f1 Clean up ugly code bits. 2013-11-10 12:30:24 +01:00
Daniele Alessandri 38c7697881 Remove useless method. 2013-11-10 12:27:15 +01:00
Daniele Alessandri b45ba55f46 Switch to protected visibility for some members of Predis\Client.
The "profile" member is actually used for caching purposes as fetching
its value from the options instance would add noticeable overhead in a
part of the client where every bit of optimization matters, for this
we decided to keep it private.
2013-11-10 12:20:20 +01:00
Daniele Alessandri b50b90aa66 Rename method. 2013-11-10 12:17:58 +01:00
Daniele Alessandri bab0cd999c Rename Predis\Client::multiExec() to Predis\Client::transaction().
Method was deprecated since Predis v0.8.5.
2013-11-09 19:56:01 +01:00
Daniele Alessandri f066356858 Slightly change the internal context factory method of Predis\Client. 2013-11-09 19:16:09 +01:00
Daniele Alessandri 7649533141 Remove some obsoleted or useless methods from Predis\Client. 2013-11-09 19:07:24 +01:00
Daniele Alessandri 089b972def Merge branch 'v0.9/client-options' 2013-11-08 12:08:26 +01:00
Daniele Alessandri b1ebc8df2f Reimplement from scratch client configuration.
This commit is a complete rewrite of the classes previously contained
in the Predis\Option namespace aimed at lowering the initialization
overhead while bringing in more consistency. The overall idea is still
the same with a mini DI container, Predis\Configuration\Options, which
carries options with values that can be initialized lazily.

The first difference with our previous implementation is that now even
user-defined options can be initialized lazily, everything needed is
an object responding to the __invoke() magic method such as a closure.
Other kind of callable arguments (strings, arrays) will be treated as
plain values. The only drawback is that we cannot pass any instance of
classes implementing __invoke() as an option value, but considered the
limited scope of our use case we can say it's more of an acceptable
compromise. Callbacks used for lazy initialization will receive two
arguments upon invokation:

  - The current instance of Predis\Configuration\Option ($options)
  - A string containing the name of the option ($option)

This is an example in actual code:

  $options = new Predis\Configuration\Options([
    'exceptions' => true,
    'profile' => '2.8',
    'distributor' => function () {
      return new Predis\Cluster\Distribution\KetamaPureRing();
    },
    'cluster' => function ($options) {
      $distr    = $options->distributor;
      $strategy = new Predis\Cluster\PredisClusterHashStrategy($distr);
      $cluster  = new Predis\Connection\PredisCluster();

      return $cluster;
    },
    'connections' => function ($options, $option) {
      $factory = $options->getDefault($option);
      $factory->define('tcp', 'Predis\Connection\PhpiredisConnection');

      return $factory;
    },
  ]);

As you can see there's very little difference compared to before in
the actual usage as most changes are under the hood. Some options such
as "exceptions" and "replication" can now correctly parse bool values
from strings (so the string "false" is not evaluated as boolean true).

While options were initially conceived to configure the client and its
behavior, the concept has matured and it's perfectly fine to consider
the use of Predis\Configuration\Options to propagate configurations to
inner parts of the library.
2013-11-08 12:08:11 +01:00
Daniele Alessandri 153758019c Diverging from the v0.8 branch (current stable).
This commit marks the start of works for the next major release of
Predis which will bring various breaking changes needed to polish the
internal design making the library even more flexible to use or extend
and, more importantly, almost stable in terms of API.

The Redis commands API exposed by Predis\Client is not going to change
much if not at all which is a good news. The most immediate changes
affecting developers will involve the renaming of a few namespaces and
classes, the removal of some previously deprecated classes and methods
and some tweaks to the current abstractions.

Right now the plan is to have a fast paced development to release this
version as soon as possible, ideally a few weeks later than Redis 2.8,
then wait to see the final definition of redis-cluster so that we can
tweak our code if needed and finally hit the v1.0.0 milestone with as
few changes as possible. Furthermore, v1.x will most likely be the
last version of Predis supporting PHP 5.3 as we will start migrating
to PHP 5.4 (or even 5.5) with v2.x, which is not going to happen soon
anyway.
2013-11-08 11:17:50 +01:00
Daniele Alessandri 8533dbdb0b Deprecate Client::pubSub() in favor of Client::pubSubLoop().
Client::pubSub() still works like usual by returning a new pub/sub
context, but it is now considered an alias of Client::pubSubLoop().

This change is necessary in preparation for the next major version
of Predis where Client::pubSub() will be used for the new PUBSUB
command introduced in Redis 2.8.
2013-11-02 18:19:32 +01:00
Daniele Alessandri 98aacd8d9a Back to development for the next patch release. 2013-11-02 18:19:31 +01:00
Daniele Alessandri cb18d67b6a Update CHANGELOG and bump VERSION. 2013-07-27 11:13:54 +02:00
Alexandru Patranescu 2d2930d24f some PHPDoc fixes in lib
and removed some unused imports also
2013-06-03 00:06:41 +03:00
Daniele Alessandri 5a735aa670 Back to development for the next patch release. 2013-03-16 12:11:37 +01:00
Daniele Alessandri 8c0498a893 Bump VERSION and update CHANGELOG. 2013-02-18 15:03:45 +01:00
Daniele Alessandri 8cbcb09c4c Remove a few unnecessary strict comparisons. 2013-02-16 17:05:12 +01:00
Daniele Alessandri 2781bd780f Fetch connection factory directly from client options. 2013-02-16 14:36:04 +01:00
Daniele Alessandri c38376dcc4 Accepts callable as first argument of Predis\Client::__construct().
Users can then use callables to wrap the creation and initialization
of the underlying connection with custom strategies:
2013-02-15 11:36:19 +01:00