Skip to content
Predis service provider for the Silex microframework
PHP
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples
lib/Predis/Silex
tests
.gitignore
.travis.yml
CHANGELOG
LICENSE
README.md
VERSION
composer.json
phpunit.xml.dist

README.md

PredisServiceProvider

This service provider for the Silex microframework enables developers to easily use Predis in their applications to connect to Redis.

NOTE: starting from commit 5a20c1c, the developers behind Silex decided to switch from the concept of extensions to the one of service providers and renamed all the interfaces and classes involved by this change. PredisExtension has been renamed to PredisServiceProvider with the release of v0.2.0 to accomodate this change, so if you need to use it with older versions of Silex you can download the previous v0.1.0.

Getting started

Starting to use this service provider is quite easy. Supposing that you already have the scheleton of your Silex application ready, you just need to register the Predis\Silex namespace to point to the path of where the source code of the provider has been placed and then add an instance to the application object:

<?php
/* ... */
$app['autoloader']->registerNamespaces(array(
    'Predis\Silex' => __DIR__.'/../vendor/PredisServiceProvider/lib',
));

$app->register(new Predis\Silex\PredisServiceProvider(), array(
    'predis.class_path' => __DIR__.'/../vendor/Predis/lib',
    'predis.parameters' => 'tcp://127.0.0.1:6379/',
    'predis.options'    => array('profile' => '2.2'),
));
/* ... */

The predis.class_path option lets you specify where to look for Predis. Both predis.parameters and predis.options are optional and they accept the same values of the constructor method of Predis\Client.

It is also possible to define multiple clients identified by aliases with their own parameters and options using predis.clients. Each client instance will be initialized lazily upon first access:

<?php
/* ... */
$app->register(new Predis\Silex\PredisServiceProvider(), array(
    'predis.class_path' => __DIR__.'/../vendor/Predis/lib',
    'predis.clients' => array(
        'first' => 'tcp://127.0.0.1:6379',
        'second' => array(
            'host' => '127.0.0.1',
            'port' => 6380,
        ),
        'third' => array(
            'parameters' => 'tcp://127.0.0.1:6381',
            'options' => array(
                'profile' => 'dev',
                'prefix' => 'silex:',
            ),
        ),
    ),
));
/* ... */

If you are looking for simple but complete examples of how to use this extension you can have a look at the examples directory that is included in the repository, or the test suite in the tests directory.

Testing

In order to be able to run the test suite of the provider you must download Composer in the root of the repository and then install the needed dependencies.

  $ wget http://getcomposer.org/composer.phar
  $ php composer.phar install
  $ phpunit

Dependencies

  • PHP >= 5.3.2
  • Predis >= 0.7.0

Project links

Author

Contributors

License

The code for PredisServiceProvider is distributed under the terms of the MIT license (see LICENSE).

Something went wrong with that request. Please try again.