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 a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.