Laravel Laravel 5.5 Laravel 5.6

Beginners guid to use Redis with Laravel Framework

Written by Yogesh Koli

What is Redis?

Redis is an open source in memory data structure store mostly use as a database, cache or a message broker on backend, Redis is advanced it uses key value storage mechanism to store the data, if you are thinking to use Redis on your project then its an outstanding open source choice available in the market to manage the data and improve application performance.

I always like to manage cache whenever it comes to manage web application user load,  iTech Empires also uses the Redis to manage cache.

In this tutorial I will give you detail on how you can install and use Redis with your Laravel new or exiting project.

Advantages using Redis with Laravel Framework

Redis supports rich data structures – 

Yes redis refers do support hight amount data structure in contain strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries so with this in mind we can play with different types of data without any issues.

Speed –  

Redis processed data very fast as it run on in-memory dataset it gives exceptionally good performance to our application, evenly it will boost website user experience

Support Messaging – 

Apart from caching Redis has ability to interchange data real-time, it is also useful for messaging and sending real-time notification to active users.

Supports Transactions – 

Redis also supports trasactinons which means we can run process one after another the commands can be queued.

Steps to install Redis on Ubuntu Operating system

Before starting to use redis with Laravel project we need to install redis server on our system, In this step I am going to show you how you can install redis on Ubuntu operating system, if you are using Ubuntu as your development environment then you can follow next steps to install:

First update your system to get it ready to install new application:

Next use bellow command to grab redis on your system:

After installing redis successfully into the system, we need to start redis server, the following command will start the redis server and it will make sure to keep redis running when you restarted your system:

Steps to install Redis on Mac Operating System

If you are on Mac Operating system then you have a couple of options, if you are using homestead on your mac for Laravel development then your good to go you don’t need to install it again because homestead has installed out of the box. another option is using homebrew, first make sure to install homebrew and then following next commands, if you have’t installed homebrew yet then use this command to install:

Use following command to install redis server:

Use this command to start redis server:

I assume that you have redis server running on your development platform, now let’s proceed further to learn how to configure redis with Laravel project and see real-time examples using redis.

Configure Redis with Laravel Framework

In this step we are going to configure redis within Laravel project, so to do that we have to install predis library into the project using composer and to do this you should have Laravel project installed and ready to use with redis, if you have existing project then not to worry your good to go if not then Creating new Laravel project is really is easy, use following command to create one:

Using Laravel installer:


Using Composer:

Okay so I assume that you have Laravel Project running and ready to rock, let’s install predis php library to support Redis operations from the project, use following command to install:

Next Laravel has provided built-in redis configuration options into the config/database.php file, go ahead and open config/database.php file into your code editor and checkout the default configuration:

The default configuration for redis should work with you development platform, however you can modify according to your redis installation if needed but at the first place you don’t need to do any changes.

Examples using Redis with Laravel

Now let’s see real time examples using redis and Laravel click here – 3 examples using redis that makes your laravel site load faster

About the author

Yogesh Koli

Yogesh Koli is a software engineer & a Blogger lives in India. He's driven by an addiction to learning and a love for adventure. he has 5+ years of experience working with the front-end, back-end, web application development, and system design.

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of