0
0
Redisquery~30 mins

Client discovery through Sentinel in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Client Discovery through Redis Sentinel
📖 Scenario: You are managing a Redis setup with Sentinel for high availability. Your application needs to discover the current master node automatically to send write commands.Redis Sentinel monitors Redis masters and their replicas, and provides the current master address to clients.
🎯 Goal: Build a simple Redis Sentinel client discovery setup that queries Sentinel to find the current master address.
📋 What You'll Learn
Create a list of Sentinel nodes with their IPs and ports
Define the name of the monitored master
Query Sentinel nodes to get the current master address
Store the master address for client use
💡 Why This Matters
🌍 Real World
Redis Sentinel is used in production to provide automatic failover and high availability. Applications need to discover the current master to send writes correctly.
💼 Career
Knowing how to interact with Redis Sentinel is important for backend developers and DevOps engineers managing scalable Redis deployments.
Progress0 / 4 steps
1
Setup Sentinel nodes list
Create a list called sentinel_nodes containing these exact tuples: ("192.168.1.10", 26379), ("192.168.1.11", 26379), and ("192.168.1.12", 26379) representing the Sentinel IP addresses and ports.
Redis
Need a hint?

Use a Python list with tuples for IP and port pairs.

2
Define monitored master name
Create a string variable called master_name and set it exactly to "mymaster", which is the name Sentinel uses to monitor the master Redis instance.
Redis
Need a hint?

Assign the exact string "mymaster" to master_name.

3
Query Sentinel for master address
Write a function called get_master_address that takes sentinel_nodes and master_name as parameters. Inside, use a for loop with variables ip and port to iterate over sentinel_nodes. For each Sentinel, connect using redis.StrictRedis(host=ip, port=port), then call sentinel_client.sentinel_get_master_addr_by_name(master_name). Return the first non-None master address found as a tuple (master_ip, master_port). If none found, return None.
Redis
Need a hint?

Use a for loop with ip, port to connect to each Sentinel and call sentinel_get_master_addr_by_name.

4
Store the discovered master address
Call the function get_master_address with sentinel_nodes and master_name, and assign the result to a variable called current_master. This variable will hold the tuple (master_ip, master_port) for client use.
Redis
Need a hint?

Assign the function call result to current_master.