Redis is a popular open-source, in-memory database written in C, often used as a caching layer for its speed and efficiency. With support for lists, strings, and sets, Redis enhances performance by storing frequently accessed data, improving user experience and web app responsiveness.
While connecting to a standalone Redis server is simple, achieving high availability requires Redis Sentinel. Sentinel automates replication failover, offers detailed monitoring, and supports master-slave configurations for reliable performance. Let’s dive deeper into how it works!
What is Master and Slave Replication?
When you create a master Redis server, you should know that several Redis slave servers can be deployed too, ideally on different nodes spread throughout numerous data centers. This way, in case the master is not reachable, any of the slave Redis servers can take its place.
Ultimately, this allows for high availability, as data can be served with minimal to no interruption whatsoever. Since Redis is so incredibly simple, there are a number of tools that can be used to create and then manage a configuration that includes a master and slave Redis server.
However, the most popular solution for maintaining Redis High Availability is to use Redis Sentinels, which generally run as different processes to monitor master-slave sets. Currently, Sentinel 2 is the latest version, and you can run it using the following command:
Redis-sentinel /path/to/sentinel.conf
Before you start using Sentinel, it is imperative that you also deploy a configuration file, as the file is used to save the system’s current state, and in case of a restart, the configuration file will be used for reloading. Without a configuration file, Redis Sentinel will not start.
Are you looking for an ETL tool to migrate your data? Migrating your data can become seamless with Hevo’s no-code intuitive platform. With Hevo, you can:
- Automate Data Extraction: Effortlessly pull data from various sources and destinations with 150+ pre-built connectors.
- Transform Data effortlessly: Use Hevo’s drag-and-drop feature to transform data with just a few clicks.
- Seamless Data Loading: Quickly load your transformed data into your desired destinations, such as BigQuery.
- Transparent Pricing: Hevo offers transparent pricing with no hidden fees, allowing you to budget effectively while scaling your data integration needs.
Try Hevo and join a growing community of 2000+ data professionals who rely on us for seamless and efficient migrations.
Get Started with Hevo for Free
Configuring for Redis High Availability
The source distribution for Redis High Availability generally comes with a file known as sentinel.conf. Think of it as a sample configuration file that you can use to easily configure Redis Sentinel.
But, if you want to configure this yourself, the code generally looks like this:
sentinel monitor master 127.0.0.1 6382 3
sentinel down-after-milliseconds master 60000
sentinel failover-timeout master 180000
sentinel parallel-syncs master 1
sentinel monitor flash 192.168.22.74 6380 3
sentinel down-after-milliseconds flash 10000
sentinel failover-timeout flash 180000
sentinel parallel-syncs flash 5
When setting up the configuration file, you have to highlight which masters you want Sentinel to monitor. This is done by giving a separate name to each master. Importantly, replicas don’t need a name, since they’re discovered automatically.
Then, Redis Sentinel will get to work, updating the configuration on its own with any new information about the replicas. The configuration file is edited and rewritten every time there’s a chance in the master-slave configuration, primarily during a failover.
The sample configuration above shows monitoring for two separate instances of Redis High Availability, each including a master and replicas (unstated figure). The master is entitled “master” and the other is called “flash.”
What is a Command Line?
- The first command tells Redis to start monitoring the “master,” specifying its address, port, and a quorum value (e.g., 3).
- The quorum represents the minimum number of Sentinels that must agree the master is unreachable before triggering a failover.
- For example, with a quorum of 3 and 7 Sentinels in the setup, at least three Sentinels must confirm the master is down to proceed.
- Once confirmed, one of these Sentinels initiates the failover process, ensuring a seamless transition to a new master.
- This mechanism ensures reliability and avoids unnecessary failover triggers.
Redis Sentinel Automatic Failover — Understanding The Process
- Redis Sentinel constantly monitors both the Master and Slave instances in the cluster to ensure everything is running smoothly.
- If a failure is detected in the Master node, the Slave servers work together to reach a quorum (an agreement among them).
- Once a quorum is achieved, Sentinel selects a Slave server and promotes it to become the new Master.
- The remaining Slave servers are reconfigured to recognize the new Master and continue functioning seamlessly.
- Sentinel is a robust distributed system with safeguards to ensure the best possible Slave server is promoted during a failover.
Other Options Available to Configure for Redis High Availability
There are a couple of other options that you should know about when dealing with the Sentinel configuration file when configuring for Redis High Availability. Generally, these include the following:
- Down-after-milliseconds
- Parallel-syncs
Down-after-milliseconds indicates the time, in milliseconds, for which a master must not be reachable before the Sentinel begins to evaluate the possibility of it being down.
Parallel-syncs define the number of replicas that can be reconfigured for use once the new master is selected as the failover process is completed.
You also have the option to configure parameters during runtime when dealing with the Redis High Availability, i.e., the Redis Sentinel configuration file.
Conclusion
If you want a robust replication setup with Redis, using Sentinel is definitely important. Not only does it simplify the replication failover process, but it makes it easy to switch quickly and efficiently. This ensures that your data is always available and that there is always an instance available, you should absolutely consider using Redis Sentinel.
Redis is an extremely powerful database that offers support for multiple data structures. If you’re using Redis, you should configure it with Redis Sentinel for high availability.
If you want to pull all your data into a data warehouse without writing a single line of code, try Hevo. Hevo lets you load data from different sources easily, moving it to its desired destination without requiring any code. If you’re using Redis, you can add Hevo Data to visualize all your data using a BI tool as well.
Hevo greatly simplifies the management process and the ETL processes for both destinations and the sources of data too.
Hevo, with its strong integration with 150+ sources and BI tools (Including 60+ Free Sources), allows you to not only export & load data but also transform & enrich your data & make it analysis-ready in a jiffy.
Want to take Hevo for a ride? Sign Up for a 14-day free trial and simplify your Data Integration process. Do check out the pricing details to understand which plan fulfills all your business needs.
Tell us about your experience of learning about the Redis High Availability Guide! Share your thoughts with us in the comments section below.
FAQs
1. Does Redis have high availability?
Yes, Redis supports high availability through features like Redis Sentinel and Redis Cluster. Sentinel provides monitoring, failover, and automatic recovery, while Redis Cluster enables data sharding and redundancy across multiple nodes to ensure availability and fault tolerance.
2. How to make Redis highly available?
To make Redis highly available, use Redis Sentinel for automatic monitoring, failover, and recovery, ensuring your primary and replica setup remains operational. Alternatively, implement a Redis Cluster to distribute data across multiple nodes, providing redundancy and fault tolerance for large-scale deployments
3. Why does Redis have 16384 slots?
Redis uses 16,384 hash slots to efficiently distribute keys across a cluster. Each key is hashed to a slot, and these slots are evenly assigned to cluster nodes. This fixed number simplifies scaling, rebalancing, and key-to-node mapping in distributed environments.
Najam specializes in leveraging data analytics to provide deep insights and solutions. With over eight years of experience in the data industry, he brings a profound understanding of data integration and analysis to every piece of content he creates.