Introduction

Redis is an open source in-memory data structure store. It is a short for Remote Dictionary Server(REDIS). It is used as a distributed in-memory key-value database for applications needing fast response times. It supports various kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, geospatial and JSON. Only Redis offers such a vast variety of data stores as compared to other key-value data store offerings.
History
Redis was developed in 2009 by Salvatore Sanfilippo to improve the scalability of his real-time web log analyzer startup. He made it open source and announced the project on Hacker news where it gained traction amongst the developer community.
What is so special about Redis?
Redis popularized the concept that a system can be considered both as a data store as well as a cache. It uses the main computer memory to modify and read data. The data is stored on the disk but only to recover the data store when it restarts.
It also provides a data model that is very unusual as compared to a RDBMS system. User commands describe specific operations to be performed on given abstract data types rather than describing a query to be executed. Therefore the data must be stored in a way which is fast to retrieve without using any secondary indexes, aggregations for other common features of traditional database systems.
Overview How Redis works internally

Redis consists of mainly two components – Redis server and Redis client. Redis server is responsible for storing data in memory, enforcing the persistence policy. Whereas Redis client is the console client or any other programming language API that can interact with Redis server to store and retrieve data.
It makes heavy use of the fork system call, to duplicate the process holding the data, so that the parent process can continue to serve clients, while the child process creates a copy of the data on disk
Persistence
By default Redis writes to disk every 2 seconds. It can be configured lower if needed. Redis offers following options for persisting data:-
- RDB (Redis Database) – Redis performs point-in-time snapshots of the dataset at specified intervals
- AOF (Append Only File) – In this mode Redis logs every write operation received by the server in an append only fashion. This can be played back to reconstruct the data on server restart. It can also rewrite the log in the background if it gets too big
- No Persistence – You can even disable persistence if all you want data to exist as long as the server is running
- RDB + AOF – You can combine both RDB and AOF mechanisms. RDB can provide perfect solution for backups, which can be set for example to run every hour or every day and can be used to recover in case of disasters. AOF can ensure all transactions are logged which can then be recovered up to the previous second. It will consume less space because an RDB is already in place. You can read the advantages and disadvantages of both approaches here – https://redis.io/docs/manual/persistence/
When to use Redis?
Redis stores data in key-value pairs in memory which can be retrieved in a fraction of a second by your application. Hence it lends itself to its most common use case of caching data needed for near-realtime systems. In addition to caching it also provides a data model which can be used to store complex datatypes in memory.
Example of a simple key value pair stored in Redis cache
key_stockname="Apple"
value_price=["close_price:140","open_price:150"]
You can also configure the key to expire at a certain interval so that new data can be cached and data refreshes can be automatically handled.
Redis Use Cases
Enterprise Caching
A basic caching layer that stores the frequently used data in-memory, so that repeated database requests can be served faster. It can also scale horizontally across the cluster without degrading the performance.
Chat, Messaging and queues
Redis supports publisher/subscriber model with pattern matching. This allows Redis to support high performance chat rooms, real-time comment streams, server feeds and server intercommunication. The Redis List data structure makes it easy to implement a lightweight queue. Lists also offer atomic operations as well as blocking capabilities making it suitable for variety of applications that require a reliable message broker or a circular list.
Geospatial
Redis offers purpose-built in-memory data structures and operators to manage real-time geospatial data at scale and speed. You can use it to add location-based features such as drive time, drive distance, and points of interest.
Machine Learning
Machine Learning applications need to quickly process a massive volume, variety and velocity of data for automatic decision making. Redis provides ability to process real-time data for use cases like Fraud detection in financial services and in gaming, bidding in ad-tech, matchmaking in dating and ride-sharing etc.
Real-Time Analytics
With its high speed in-memory database Redis lends itself to the use case to ingest, process and analyze real-time data with sub-second latency. It is an ideal choice for real-time analytics use cases such as social media analytics, ad targeting personalization and IoT.
Advanced Concepts
From here you can go and read about the following two advanced topics in Redis and also look for getting started examples
- Redis Cluster
- Redis Sharding
Conclusion
In this article I covered the introduction to Redis along with architecture and possible use cases. In upcoming articles I will cover the local installation, cloud Redis, getting started code examples and advanced enterprise level concepts like sharding and clustering. Stay Tuned and Bookmark this page!