Recommend this page to a friend! |
Classes of Khoa Bui | PHP Fast Cache | src/phpFastCache/_extensions/predis-1.0/README.md | Download |
|
DownloadPredisPredis is a flexible and feature-complete Redis client library for PHP >= 5.3. By default Predis does not require any additional C extension, but it can be optionally paired with phpiredis to lower the overhead of serializing and parsing the Redis protocol. An asynchronous implementation of the client, albeit experimental, is also available through Predis\Async. Predis can be used with HHVM >= 2.3.0, but there are no guarantees you will
not run into unexpected issues (especially when the JIT compiler is enabled via More details about the project can be found in our frequently asked questions section or on the online wiki. Main features
How to use PredisPredis is available on Packagist which allows a quick installation using Composer. Alternatively, the library can be found on our own PEAR channel for a more traditional installation via PEAR. Ultimately, archives of each release are available on GitHub. Loading the libraryPredis relies on the autoloading features of PHP to load its files when needed and complies with the PSR-4 standard. Autoloading is handled automatically when dependencies are managed through Composer, but it is also possible to leverage its own autoloader in projects or scripts not having any autoload facility:
It is possible to easily create a phar archive from
the repository just by launching Connecting to RedisWhen not specifying any connection parameter to create a new client, Predis assumes
Connection parameters can be supplied either in the form of URI strings or named arrays. While the latter is the preferred way to supply parameters, URI strings can be useful for quick configurations or when parameters are read from a non-structured source:
When an array of connection parameters is provided, Predis automatically works in cluster mode using client-side sharding. Both named arrays and URI strings can be mixed when providing configurations for each node:
The actual list of supported connection parameters can vary depending on each connection backend so it is recommended to refer to their specific documentation or implementation for details. Client configurationVarious aspects of the client can be configured simply by passing options to the second argument of
Options are managed using a mini DI-alike container and their values are usually lazily initialized only when needed. Predis by default supports the following options: - Users can provide custom options with their values or lazy callable initializers that are stored in the options container for later use through the library. Aggregate connectionsPredis is able to aggregate multiple connections which is the base for cluster and replication. By default the client implements a cluster of nodes using either client-side sharding (default) or a Redis-backed solution using redis-cluster. As for replication, Predis can handle a single-master and multiple-slaves setup by executing read operations on slaves and switching to the master for write operations. The replication behavior is fully configurable. ReplicationThe client can be configured to work in a master / slave replication setup by executing read-only commands on slave nodes and automatically switch to the master node as soon as a command performing a write operation is executed. This is the basic configuration needed to work with replication:
While Predis is able to distinguish commands performing write and read-only operations,
The ClusterSimply passing an array of connection parameters to the client constructor configures Predis to work in cluster mode using client-side sharding. If you, on the other hand, want to leverage Redis >= 3.0 nodes coordinated by redis-cluster, then the client must be initialized like this:
When using redis-cluster, it is not necessary to pass all of the nodes that compose your cluster but you can simply specify only a few nodes: Predis will automatically fetch the full and updated slots map directly from Redis by contacting one of the servers. __NOTE__: our support for redis-cluster does not currently consider master / slave replication but this feature will be added in a future release of this library. Command pipelinesPipelining can help with performances when many commands need to be sent to a server by reducing the latency introduced by network round-trip timings. Pipelining also works with aggregate connections. The client can execute the pipeline inside a callable block or return a pipeline instance with the ability to chain commands thanks to its fluent interface:
TransactionsThe client provides an abstraction for Redis transactions based on
This abstraction can perform check-and-set operations thanks to Adding new commandsWhile we try to update Predis to stay up to date with all the commands available in Redis, you might prefer to stick with an older version of the library or provide a different way to filter arguments or parse responses for specific commands. To achieve that, Predis provides the ability to implement new command classes to define or override commands in the server profiles used by the client:
There is also a method to send raw commands without filtering their arguments or parsing responses. Users must provide the arguments list as an array, following the command signatures as defined by the Redis documentation for commands:
Script commandsWhile it is possible to leverage Lua scripting on Redis 2.6+ using
Customizable connection backendsPredis can use different connection backends to connect to Redis. Two of them leverage a third party
extension such as phpiredis resulting in major performance gains
especially when dealing with big multibulk responses. While one is based on PHP streams, the other
is based on socket resources provided by
Developers can create their own connection classes to support whole new network backends, extend
existing ones or provide completely different implementations. Connection classes must implement
For a more in-depth insight on how to create new connection backends you can refer to the actual
implementation of the standard connection classes available in the DevelopmentReporting bugs and contributing codeContributions to Predis are highly appreciated either in the form of pull requests for new features, bug fixes, or just bug reports. We only ask you to adhere to a basic set of rules before submitting your changes or filing bugs on the issue tracker to make it easier for everyone to stay consistent while working on the project. Test suite__ATTENTION__: Do not ever run the test suite shipped with Predis against instances of Redis running in production environments or containing data you are interested in! Predis has a comprehensive test suite covering every aspect of the library. This test suite performs
integration tests against a running instance of Redis (>= 2.4.0 is required) to verify the correct
behavior of the implementation of each command and automatically skips commands not defined in the
specified Redis profile. If you do not have Redis up and running, integration tests can be disabled.
By default the test suite is configured to execute integration tests using the profile for Redis 2.8
(which is the current stable version of Redis) but can optionally target a Redis instance built from
the Predis uses Travis CI for continuous integration and the history for past and current builds can be found on its project page. OtherProject related linksAuthorLicenseThe code for Predis is distributed under the terms of the MIT license (see LICENSE). |