Laravel

Configure Redis with Laravel/Lumen 5.8

What is Redis

Redis is a storage server that stores data in memory for very fast Read/Write transactions.

It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

Read more about Redis.

Laravel/Lumen supports Redis integration by default, before you start using Redis you need to install the predis/predis package via Composer:

composer require predis/predis

In order to configure Redis in Laravel, you can change these settings in config/database.php.

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

If you want to manage these settings by .env file do the following.

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => env('REDIS_HOST', '127.0.0.1'),
        'port'     => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DATABASE', 0),
    ],

],

And your .env file add:

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DATABASE=0

If you are using Laravel remember to run:

php artisan config:clear

And if you are using Lumen remember to add:

$app->register(\Illuminate\Redis\RedisServiceProvider::class);
in bootstrap/app.php

That’s it for configurations, enjoy!

About the author

Danyal Ali Butt

I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.

View all posts