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!

Author: Danyal
I'm skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk