Optimize and faster magento site with redis cache

Faster Magento With Redis Cache

Overview :

Redis Cache is an open source, advanced key-value store and a serious solution for building high-performance, scalable web applications.

Features of Redis :

  • Redis cache handle persistent data
  • Redis cache is more efficient because it consumes comparatively fewer memory resources for metadata.
  • Redis supports master-slave replication.
  • Redis has stronger data structures.
  • Redis key-length has a maximum of 2GB.
  • Redis support for multiple databases using same server instance.

As you see the features of Redis server, you will understand why redis is more compatible to use with Magento platform and also the configuration of redis with Magento is very easy.

In this article, I’ll do my best to describe steps to the configuration of Redis as cache and session backend with Magento.

Requirements :

Below are the details of server hardware, os version, and redis version, Magento version which I have used while configuring redis with Magento.

Server Details :

  • OS   : Debian 8.5 Jessie
  • CPU : 2 Core
  • RAM : 4 GB

Application Details :-

  • Redis Version      : 3.2.3
  • Magento Version :

Redis server installation steps 

Step 1 : Dependency Package

Before start installing Redis server you need to install below dependency packages using the apt-get command.


  • apt-get update
  • apt-get install build-essential
  • apt-get install tcl8.5

Step 2 : Install Redis Server

Installing the redis-server package on Debian 8 (Jessie) is as easy as running the following command on terminal.

apt-get update
apt-get install redis-server

Install Redis Server from source code

Step 1 : Download Redis Package

With all of the prerequisites and dependencies downloaded to the server, we can go ahead and begin to install redis from source.

  • cd /opt/
  • wget http://download.redis.io/releases/redis-stable.tar.gz
  • make
  • make install

Once you installed the Redis server you will get the script in “utils” directory which helps to create redis daemon to run as background process.

  • cd /opt/redis-stable/utils
  • ./install_server.sh or bash install_server.sh

After executing above .sh file it will ask you some questions to configure redis so just keep the default settings by pressing enter.

Redis Server installation

Step 2 : Start & Stop Redis commands,

Use below commands to start|stop|restart Redis server.

  • service redis_6379 start
  • service redis_6379 stop
  • service redis_6379 restart
  • service redis_6379 status

Step 3 : Use and Check working of Redis

With below command, you can check the working of Redis server and also you will see the values or parameters of redis.

  • redis-cli> info

Step 4 : Set Redis on boot

After setting up Redis server make sure you will add the redis_6379 service in the auto start which means whenever you will reboot your server this service will start in the boot.
Use below command :

  • update-rc.d redis_6379 defaults

Step 5 : Secure Redis Server

Security is a very important part when you setting up any service on a production server so always make a habit of running such services on private ip of your server or
For binding localhost IP or server private IP Open the Redis configuration file for editing:

vim /etc/redis/redis.conf

#If below the line is commented then uncomment it.


Save and close the file.

Restart service to reflect the configuration changes,

  • service redis_6379 restart

Here, we have completed the process to install & configure Redis Cache Server.

The configuration of Redis with Magento

Step 1 : Enable the Cm_RedisSession module

The Cm_RedisSession module is disabled by default.

Magento disables the module to avoid non-essential connection tries to Redis when you choose to use a different session storage method.

To enable open Cm_RedisSession.xml file which is resides under “app/etc/modules/” directory.

Step 2 : Add Session and Cache code in local.xml

After enabling session module you need to add the below code for session storage and cache storage. This code will be use under the local.xml file.
With the help of this code, you will mention Redis database to store session value and cache content.
In below code I have explained you each line in comment box remove this comments when you use this code in your environment.
Open local.xml file and comment default session save entry and add below code,

Redis Session Storage
Add This For Session Storage
Add This For Cache Storage

Step 3 : Verify Magento working with Redis

To verify configuration is working successfully run below command in terminal,

  • redis-cli monitor

and reload your Magento homepage.

Some get and set commands will be executed. This shows Magento is communicating with Redis server.

To exit monitor mode, press CTRL+C

Redis Commands

To start Redis Client use below command which connects you to the local server.

Now use the command in redis panel.

  • redis-cli>PING
    o/p: PONG

Ping command checks whether redis are running or not.

Redis command to Flush Cache and Session

  • redis-cli>info [This will shows complete redis information with parameters and available database on redis server]
    ## under Keyspace will provide available database info.
    # Keyspace
    db1:keys=992,expires=423,avg_ttl=7627501>SELECT 0 [With select command choose db to flush]>flushdb>SELECT 1>flushdb>flushall [flushall command use to flush all dbs with single command]

Note : If you are on production server never flush session database otherwise all your customer’s session will be flush and they will be disconnecting from the site.

Redis FlushDB module [Magento-RedisManager]

When we make some coding level changes we need to flush cache from redis which helps to show or reflect newer changes in files but to login on the server then connecting to redis and use the command line to flush redis cache is very time-consuming process.

So we have redis module called Magento-Redismanager which will work through Magento Admin panel and helps you to flush Redis cache, sessions.

Step 1. Download Magento-Redismanager

Now download Redismanger on the server under /opt or any directory then unzip it.

  • cd /opt/
  • wget https://github.com/steverobbins/Magento-Redismanager/archive/master.zip
  • unzip master.zip

Step 2 : Sync RedisManager Code

After unzipped master.zip file you will have “Magento-Redismanager-master” directory. Under “Magento-Redismanager-master” go to src/ directory and sync app and skin folder to your magento-codebase/app and magento-codebase/skin directory.

  • cd Magento-Redismanager-master/src
  • rsync -avzP app/* magento-codebase/app/
  • rsync -avzP skin/* magento-codebase/skin/

Step 3 : Login Magento Admin Panel

Now login to Magento admin panel and open “System–>Redis Management”.

In Redis Management console you will have options to flush cache and session db’s.

Magento Redis Manager
Magento Redis Manager

I hope you like the article if you find any difficulties while installing Redis Cache with magento then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.

Related Posts :

Latest Comments
  1. Alex July 21, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *