Redis – Introduction

Redis (REmote DIctionary Server) is an in-memory NoSQL key-value DBMS (Database Management System), it was created to catalogue information distinguishing it with a key that allows immediate recovery.

In the last few years it has established itself as one of the most used database types in the world, and the most used among the NoSQL after MongoDB (a document based DBMS & not a key-value one),
One of the reasons of this success is Redis’s ability to store and manipulate high-level data types, fundamental data structures such as: lists, maps, sets, ordered sets, expiring keys & hashes.

Thanks to it’s exceptional performance, simplicity & atomic operations Redis lends itself to solving problems that are difficult or perform poorly with any traditional relational DBMS.

 

Key Features:

open-source (BSD License).
Lightweight with no Dependencies, Redis is written C with no external dependencies. Works well in all POSIX environments. Windows is not officially supported, but there is an experimental attempt provided by Microsoft.
High Performance: Redis make usage of in-memory data to optimize performance, while still contemplating several persistent disk rescue mechanisms.
High-Level Data Structures: Redis provides five possible data types for the values associated to the keys: strings, lists, sets, hashes, and sorted sets. And handles some operations that are uniques to some data types (like setting expiration to keys, incrementing values).
UDF* functions are based on Lua scripting (yes, you can extend & use your own defined functions)
Easy to use clients, for almost every major stack (Java, PHP, C#, Python, Javascript….Etc) .
Redis Cluster is production-ready since April 1st, 2015, requiring Redis 3.0 or higher.

 

The Key/Value nature of this DMBS makes it suitable for different usages such as:

Caching, due to its high performance, many developers are using it as a cache layer to accelerate applications and reduce network bandwith, with the easiness to persist the data to disk, it becomes a good alternative to the traditional memcached.
Queuing Projects such as Resque, Kue, Sidekiq, RQ, RestMQ, Huey, Disque uses Redis as the backend for queueing background jobs.
Counters & Analytics, atomic commands such as HINCRBY, allow for a simple and thread-save implementation of counters (as there is no need to read the data before incrementing, and there are no database schemas to update).
PubSub, since Redis 2.0, it provides the capability to distribute data utilizing the Publish/Subscribe messaging paradigm.

Some big companies using Redis:

Github, one of the early adopters, Github has developed and open-sourced the Resque library, to facilitate the execution of background jobs that have been placed on a queue. More on how Github uses Redis for their job queueing needs.

Twitter deployed a massive Redis cluster to store the timelines for all users, utilizing the list data structure. View the presentation given by Twitter on how they distribute timelines at scale.

Pinterest – Stores the user follower graphs in a Redis cluster where data is sharded across hundreds of instances, the Pinterest software engineers and architects had MySQL and Memcache already in place, however the caching solution had already reached their limits, and to better serve their users the cache needed to be expanded. More on how Pinterest is using Redis.

 

 

In fine, Redis could be used as any relational DBMS thanks to the keys and various data types to persist data to disk.

This guide’s aimed to help you step by step in every major aspect of Redis, from basic interactions in the console to more advanced clustering concepts, it’s simple and you can start testing it online on try.Redis.io (in which you can find also other exercises rather than applying our examples).