2017 © Pedro Peláez
 

library laravel-phpredis

phpredis library for laravel

image

barbery/laravel-phpredis

phpredis library for laravel

  • Friday, April 8, 2016
  • by barbery
  • Repository
  • 2 Watchers
  • 8 Stars
  • 236 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

laravel-phpredis

this is the library provide phpredis support in the laravel framework, clearly it support redis cluster too., (*1)

feature

  1. this library implement redis driver in Cache and Session, and Queue, you can easy to use it.
  2. implement redis pipeline just like the laravel document introduce
  3. you can customize your serilize and unserilize function
  4. you can customize your cache expired time default unit

requirements

  • PHP >= 5.6.x
  • PhpRedis
  • Laravel >= 5.2.x

install

You can install it by composer, just execute below command, (*2)

for laravel >= 5.4

Since laravel 5.4, laravel already support phpredis dirver. So, you don't need to use this library. More info, (*3)

for laravel >= 5.3

composer require barbery/laravel-phpredis:dev-master

for laravel >= 5.2

composer require barbery/laravel-phpredis:v5.2.x-dev

config

If you want to completely use phpredis instead of predis... You should add below config to your config/app.php file:, (*4)

'providers' => [
        // ...
        // YOUR OTHER PROVIDERS SETTING
        // ...
        // And you should commend those system's provider as below
        // Illuminate\Redis\RedisServiceProvider::class,

        // add this to your providers
        Barbery\Providers\RedisServiceProvider::class,
]


aliases => [
        // you must rename the Redis Key name, because it's conflict with the \Redis class provide by phpredis
        // may be you can rename it to MyRedis, So, you can use it like that:
        // MyRedis::get('key'); MyRedis::set('key', 'value'); MyRedis::pipeline(function($pipe){YOUR_CODE});
        'MyRedis' => Illuminate\Support\Facades\Redis::class,
]
// add config to `config/database.php`
'redis' => [
        // if this true, will enable redis cluster mode
        'cluster' => env('REDIS_CLUSTER', false),

        // defualt config is for single redis mode not cluster
        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
            // can take one of the values:
            // Redis::SERIALIZER_NONE, 'none',
            // Redis::SERIALIZER_PHP, 'php',
            // Redis::SERIALIZER_IGBINARY, 'igbinary'
            'serializer' => env('REDIS_SERIALIZER', Redis::SERIALIZER_PHP),
        ],

        // this is for redis cluster mode
        'clusterConfig' => [
            // cluster options
            'options' => [
                'failover' => env('REDIS_CLUSTER_FAILOVER', RedisCluster::FAILOVER_ERROR),
                'read_timeout' => env('REDIS_CLUSTER_READ_TIMEOUT', 3),
                'timeout' => env('REDIS_CLUSTER_TIMEOUT', 3),
                'persistent' => env('REDIS_CLUSTER_PERSISTENT', false),
            ],
            // put your cluster master node here
            [
                'host' => env('REDIS_HOST_1'),
                'port' => env('REDIS_PORT_1'),
            ],
            [
                'host' => env('REDIS_HOST_2'),
                'port' => env('REDIS_PORT_2'),
            ],
            [
                'host' => env('REDIS_HOST_3'),
                'port' => env('REDIS_PORT_3'),
            ],
        ],
    ],

Advance config

The default unit in laravel is minutes, if you want to change it, you can add config in your app/cache.php, (*5)

'stores' => [
        // YOUR OTHER SETTING
        // ...

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            // add this config to change the default unit, it can be 'second','minute','hour'
            'defaultUnit' => 'second',
            // if you don't set encodeFunc and decodeFunc,
            // default to use php serialize and unserialize to encode/decode value
            // below setting show you how to change it to use json_encode/json_decode to encode/decode value
            'encodeFunc' => function($value){return json_encode($value);},
            'decodeFunc' => function($value){return json_decode($value, true);},
        ],
    ],

Issue

Because Laravel 5.3.x use Lua script to migrate the queue job, and the redis cluster is not support. So if you use Laravel 5.3.x with redis cluster mode, then do not use the RedisQueue., (*6)

The Versions

08/04 2016

v5.2.x-dev

5.2.9999999.9999999-dev https://github.com/Barbery/laravel-phpredis

phpredis library for laravel

  Sources   Download

BSD

The Requires

  • php >=5.6.0

 

laravel phpredis laravel-phpredis redisserviceprovider redisstore

08/04 2016

dev-master

9999999-dev https://github.com/Barbery/laravel-phpredis

phpredis library for laravel

  Sources   Download

BSD

The Requires

  • php >=5.6.0

 

laravel phpredis laravel-phpredis redisserviceprovider redisstore