Arun Chinnachamy bio photo

Arun Chinnachamy

I am a chemical Engineer from BITS-Pilani. Right now, I work as Technology Lead at MySmartPrice. This is just a place where I write about the things I work and think.

Email Twitter Facebook Github

Redis - A Key-Value pair High Performance NoSQL Database. Why you should consider it? and Redis Installation in Ubuntu and Debian System.

In search of High Performance NoSQL database, I came across Redis few months ago. I installed in my Work Machine and started exploring the possibilities and How to use Redis for implementing Product Search Filters at The results were mind blowing and exactly as promised in the Redis official website. In this post, I will try to explain the installation procedure for Redis in Debian/Ubuntu and also help you decide when to use Redis.

Why should you consider Redis?

  • Redis is crazy fast key-value engine
  • Using the Collection types, you can create complex data structures required for your applications
  • The Asynchronous snapshot of the data is a huge boon. It gives the persistence with little penalty.
  • Auto expiry of the keys is another big addition when dealing with cache data.

Few Drawbacks of Redis:

  • Being a in memory data storehouse, you need to have a huge RAM if you want to handle huge data banks. Even a huge data store will fit into redis comfortably. Check the benchmarking results here. Even a 10000 sets, each with 1000 Records takes little more than a GB of RAM. With RAM prices going down, I do not find this as a major drawback.
  • Second thing is, loss of data when your system fails between the snapshots. This could be avoided through the proper design of your system and configuration.

Where should you deploy Redis?

  • Redis will act as an excellent cache system. You can replace your memcache with Redis which will provide you more flexibility and performance. With persistence and reduced round trips to database, it makes your cache system a better one. The auto expires and TTL are absolute plus for caching system.
  • Redis as Real Time Analytics system. If you want to track some events or data realtime, you will not be failed by Redis’s performance. It will provide the ultra fast inserts and access to your data.
  • Redis as Counter. Redis with all the inbuilt Queue, Sets, Sorted sets etc will act as the best NOSQL Database for handling leader boards, Counters, voting systems and real time stats. The union and Intersection provided in sets comes handy. Now coming to the installation procedure of Redis, I will explain how to install and configure redis in Ubuntu/Debian.

If you want to take the road less travelled by building the redis from source and do the configuration manually rather than letting aptitude to do that for you, you should go here. The advantage being you will be installing the latest stable version of redis rather than usual old version in Debian Repository.

Redis Installation and Configuration

You can install redis in Ubuntu using the aptitute package manager. Type the following command in the terminal.

sudo apt-get install redis-server

Once finished, the default configuration file will be available in


There are couple of variables which you might find it interesting and necessary to configure based on the application you work.

Depending on your preference, Change the port. This is the port in which Redis will listen for tcp connections from applications.

port 6379

If you want Redis to listen only to localhost, uncomment the following line. If not, the server will listen to all available networks.


I personally prefer to timeout the idle connections to prevent stale connections. If you think the same way, set the timeout something around 30 seconds.

timeout 30

If you like to protect your data with a password authentication, you need to uncomment and provide the password in the following line

requirepass {password}

By default, Redis server has 16 databases. If you are not planning to use 16 databases, set the value accordingly.

databases 16

As told above, Redis takes a snapshot of data depending on the configuration as a file. The persistence can be controlled using the following lines

#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#   Note: you can disable saving at all commenting all the "save" lines.

save 900 1
save 300 10
save 60 10000</pre>

Restart the redis server by running the following command in terminal

sudo /etc/init.d/redis restart

You can test the redis server by telnetting to the post specified in the configuration.

In terminal,

telnet {port}

If you have set the password, you need to authenticate before executing any commands using AUTH command. For complete set of data types and command, visit Redis Command Reference.

Now your redis server is up and running, I will explain how to connect to Redis server through PHP using Predis in my next post. If you come across any difficulty, feel free to post a comment, I will be happy to assist you.