Introduction
Redis is an in-memory data structure used as a database, cache, message broker, and streaming engine. It offers built-in Replication, Lua scripting, LRU eviction, transactions, several levels of on-disk persistence, Redis Sentinel for high availability, and Redis Cluster for automatic partitioning. You can use Redis from most programming languages.
Redis is open-source (BSD licence). Redis allows data structures like strings, hashes, lists, sets, sorted sets with range searches, bitmaps, hyperloglogs, geographic indexes, and streams.
You can install Redis from here.
A leader-follower (master-replica) replication is used and configured at the base of Redis replication (excluding the high availability features offered as an additional layer by Redis Cluster or Redis Sentinel). It enables replica Redis instances to be identical to master ones. When the link between the replica and the master breaks, the replica will automatically reconnect and seek to be an exact clone of the master, regardless of what happens to the master.
There are three primary mechanisms in Redis Replication.
- When a master and replica instance is well-connected, the master keeps the replica up to date by delivering a stream of commands to the replica to replicate the effects on the master dataset caused by: client writes, keys expired, evicted, or any other action modifying the master dataset.
- When the master-replica link is broken due to network troubles or a timeout in either the master or the replica, the replica reconnects and performs a partial resynchronization, which means it will only try to obtain the portion of the stream of commands it lost during the disconnection.
- If a partial resynchronization is not achievable, the replica will request a full resynchronization. The master creates a snapshot of all of its data, sends it to the replica, and then continues to deliver the stream of commands as the dataset changes.
Redis supports high availability and failover recovery
Redis uses asynchronous Replication by default, which is the most natural replication mode for most Redis use cases due to its low latency and great speed. On the other hand, Redis replicas asynchronously acknowledge the amount of data they got from the master regularly. As a result, the master does not have to wait for a command to be processed by the replicas every time, but it does know, if necessary, which replica has already processed which instruction. This enables optional synchronous Replication.
Clients can use the WAIT command to request synchronous Replication of specific data. However, WAIT can only ensure that the specified number of acknowledged copies are present in the other Redis instances; it does not transform a collection of Redis instances into a CP system with solid consistency: acknowledged writes can still be lost during a failover, depending on the Redis persistence configuration. However, using WAIT, the chances of losing a write after a failure event considerably decrease, especially for challenging failure modes to trigger.
Redis Sentinel provides high availability for Redis. Redis Sentinel also serves as a configuration provider for clients and does additional functions like monitoring and notifications.
- Monitoring Sentinel monitors the health of your master and replica instances regularly.
- Notification Sentinel can use an API to alert the system administrator or other computer applications when one of the monitored Redis instances has a problem.
- Automatic failover: If a master fails, Sentinel can initiate a failover process in which a replica is promoted to master, the other extra replicas are reconfigured to use the new master, and the Redis server apps are told of the new address to use when connecting.
- Configuration provider Sentinel: Clients connect to Sentinels to get the address of the current Redis master in charge of certain services. Sentinels will report the new address if there is a failover.
Check out the Redis Sentinel or Redis Cluster documentation for additional details on high availability and failover.





