Question: How can you scale Redis using Sentinel?


Redis Sentinel provides high availability for Redis. In practical terms, this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures.

Here's an overview of how to scale Redis with Sentinel:

  1. Set Up Multiple Redis Instances: You'll need more than one Redis instance for Sentinel to work because it operates based on a master-slave model. The slave instances will replicate the data of the master. If the master fails, one of the slaves can take over.
redis-server /path/to/redis.conf --port 6380 --slaveof 6379 redis-server /path/to/redis.conf --port 6381 --slaveof 6379

This will start two Redis instances in slave mode, replicating the master at port 6379.

  1. Configure Sentinels: For each Redis instance, you'll need to configure a Sentinel. A good practice is to have at least three Sentinel instances to maintain a quorum.

For example, a basic Sentinel configuration for monitoring a master could look like this:

sentinel monitor mymaster 6379 2 sentinel down-after-milliseconds mymaster 5000 sentinel failover-timeout mymaster 10000
  1. Start Your Sentinels: Once configured, you can start your Sentinels. They'll begin monitoring your Redis instances right away.
redis-sentinel /path/to/sentinel.conf
  1. Testing: You can test your setup by shutting down the master instance and observing one of the slaves getting promoted to master by the Sentinels.

Remember that scaling with Redis Sentinel primarily provides high availability rather than load distribution. If you need to distribute reads, you'd need to implement read queries to slave instances in your application. For write scaling, you might want to look at sharding techniques or use a solution like Redis Cluster.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.