Redis Tutorial Part 1 – Introduction

Redis – Remote Dictionary Server

Redis (Remote Dictionary Server) is an opensource key-value store. It can be used as a database, cache and message broker. Redis is an in-memory store which means that it primarily relies on main memory/primary memory for data storage in comparison to other database storages like Mysql that relies on disk storage.


Redis is written in C language and it supports cross-platform. In-memory databases like Redis are faster compared to disk storage databases like Mysql.

Redis is a key-value store. Which means that data is stored like


The value john an be accessed using the key name. Key value is a string.

Redis is single-threaded(One operation at a time) fast and scalable. The speed allows redis to be used as cache memory.

Install Redis on Linux

sudo apt-get update

sudo apt-get install redis-server

For Redis server


For Redis Command Line Interface


To get configuration for redis goto redis-cli.type CONFIG type of configuration to get configuration values in redis.conf.


There are two processes in Redis architecture.

REDIS-CLIENT – Manages client interaction
REDIS-SERVER – Manages data storage in the memory and forms the major part of the Redis architecture.

Single Redis instance can manage multiple redis databases


Persistence of data inside a Redis Database

Persistence of data means how long the data is stored in the redis database. Redis is an in-memory DB, there is a risk of losing data when the system powers off. This can be overcome by using the persistence feature which writes the data into the disk.


There are two different options for persistence in Redis :




In snapshotting, point-in-time copy of the Redis data, also known as a snapshot, is created.It is a binary file with extension .rdb.Snapshotting is achieved by using

BGSAVE command: Calls fork() and create a snapshot in database
Save lines in the config file: Redis can be configured to perform save operation when there are N changes in the dataset every S seconds. SAVE N S
SAVE command: When a SAVE command is called explicitly, snapshotting is done


Append Only File (AOF), records the changes in the data that occur by writing each change to the end of the file. You can enable this by changing AOF to true in the configuration file. The AOF persistence writes every time an operation is received by the server, that will be played again at server startup.



Clustering in Redis means data is split/shared among multiple computers. These computers are called nodes,

More data in a cluster as it has a group of computers.

Data Structures in Redis

Redis has five data structures


Lists -LPUSH and RPUSH to push to head and tail of a list

Sets -SADD to add data to set


Sorted sets


Redis Sentinel

System designed to help manage Redis instances. As we discussed earlier one Redis instance can be master and other instances can be slaves. The slaves can have exact data copies of the master server. The master will have replication ID. The biggest advantage of this architecture is that the slave can act as a master if the master fails.

More on sentinels in the next tutorial

No Comments

Leave a Reply

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