Separate Redis Store in Laravel

Hafiq Iqmal
4 min readMar 21, 2021
Credit to https://www.techalyst.com/

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets.

In this article, I will show how to separate the Redis configuration for cache, session and queue. Why separate? For me, its :-

  • Easier in terms of application debugging
  • Less data losses
  • More application control in-memory storage
  • Multiple connections
  • Best production oriented configuration.

Laravel have out-of-the-box Redis configuration which give you freedom to assign your connection and storage for your application.

Here is the default connection configuration in database.php

'redis' => [

'client' => env('REDIS_CLIENT', 'phpredis'),

'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],

'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
],

--

--

Hafiq Iqmal
Hafiq Iqmal

Written by Hafiq Iqmal

Technical Lead | Software Engineer | Laravel Enthusiasts | Tech writer | UiTM Alumni | Husband | Proud father of a beautiful daughter

No responses yet