Redis Caching & Messaging (Pub/Sub, Streams) · Aula

Redis Sentinel para alta disponibilidade

Configure o Redis Sentinel para gerenciar automaticamente a alternância em caso de falha e garantir a disponibilidade contínua do serviço.

Aula 2 de 411 etapas

Redis Sentinel para alta disponibilidade é uma aula grátis de Redis Caching & Messaging (Pub/Sub, Streams) no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Redis Caching & Messaging (Pub/Sub, Streams), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Redis Caching & Messaging (Pub/Sub, Streams) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

High Availability with Sentinel

When using Redis replication, what happens if your master server suddenly fails? Your application might go down!

This is where Redis Sentinel comes in. It's designed to make your Redis deployments highly available by automatically handling master failures.

Sentinel's Key Roles

Redis Sentinel isn't just one process; it's a distributed system of Sentinel instances. Each Sentinel has three main jobs:

  • Monitoring: Constantly checks if your master and replica instances are working correctly.
  • Notification: Alerts system administrators or other computer programs when a monitored Redis instance goes wrong.
  • Automatic Failover: If a master fails, Sentinel can start a failover process where a replica is promoted to master, and other replicas are reconfigured.

Sentinel Architecture Overview

A typical Sentinel setup involves:

  • One Redis master instance.
  • One or more Redis replica instances.
  • At least three Sentinel instances running on separate servers.

The Sentinels constantly communicate with each other and with the Redis instances to maintain a consistent view of the system's health.

Configuring a Sentinel

Each Sentinel instance needs a configuration file, typically named sentinel.conf. Here's a basic example. The key directive is sentinel monitor:

  • mymaster: The name you give your master set.
  • 127.0.0.1 6379: The master's IP and port.
  • 2: The quorum, explained next.
# Example sentinel.conf
port 26379
daemonize yes

# Monitor the master named 'mymaster'
sentinel monitor mymaster 127.0.0.1 6379 2

# How long a master must be unreachable before marked DOWN
sentinel down-after-milliseconds mymaster 5000

# Timeout for failover operations
sentinel failover-timeout mymaster 60000

Understanding Quorum

The quorum (the 2 in our config) is a crucial concept. It's the minimum number of Sentinels that must agree that a master is down before a failover process can be initiated.

This prevents a single Sentinel (or a network issue affecting only one Sentinel) from triggering an unnecessary failover, ensuring reliability.

Launching a Sentinel Instance

Once your sentinel.conf file is ready, you can start a Sentinel instance using the redis-sentinel command, pointing it to your config file.

You would typically run multiple Sentinels on different machines for true high availability.

redis-sentinel /path/to/sentinel.conf

Monitoring with Sentinel CLI

You can connect to a Sentinel instance using redis-cli (using the Sentinel's port, e.g., 26379) and query its status. The info sentinel command provides a wealth of information.

redis-cli -p 26379 info sentinel

The Failover Process in Action

When a master fails:

  1. Sentinels detect the master is unreachable.
  2. If enough Sentinels (the quorum) agree, they elect a leader Sentinel.
  3. The leader Sentinel promotes one of the healthy replicas to be the new master.
  4. The other replicas are reconfigured to replicate from the new master.
  5. Applications are notified of the new master's address.

Client Connectivity with Sentinel

Applications don't connect directly to the Redis master's IP and port. Instead, they are configured to connect to one or more Sentinel instances.

The client library then asks Sentinel for the current master's address. This means applications don't need to be reconfigured manually after a failover; Sentinel handles it transparently!

Sentinel Feature Check

Which of the following is NOT a primary function of Redis Sentinel?

Sentinel Recap & Next Steps

You've learned that Redis Sentinel is essential for creating highly available Redis deployments. It monitors your instances, performs automatic failovers, and keeps your applications connected even when a master goes down.

By using Sentinel, you significantly reduce downtime and improve the resilience of your Redis-backed applications. Next, we'll explore Redis Cluster for even greater scalability!

Grátis para começar

Aprenda Redis Caching & Messaging (Pub/Sub, Streams) com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
12
Aulas
48

Perguntas Frequentes

A aula “Redis Sentinel para alta disponibilidade” é grátis?

Sim — o texto completo de “Redis Sentinel para alta disponibilidade” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Redis Caching & Messaging (Pub/Sub, Streams), atualize para CoddyKit PRO. O curso de Redis Caching & Messaging (Pub/Sub, Streams) inclui 4 aulas no total.

O que vou aprender em “Redis Sentinel para alta disponibilidade”?

Configure o Redis Sentinel para gerenciar automaticamente a alternância em caso de falha e garantir a disponibilidade contínua do serviço. Você pratica Redis Caching & Messaging (Pub/Sub, Streams) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Redis Caching & Messaging (Pub/Sub, Streams)?

Nenhuma experiência prévia é necessária. Redis Caching & Messaging (Pub/Sub, Streams) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.

Quanto tempo leva a aula “Redis Sentinel para alta disponibilidade”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Redis Caching & Messaging (Pub/Sub, Streams)?

Sim. Cada aula de Redis Caching & Messaging (Pub/Sub, Streams) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Replicação do Redis para redundância
  2. Redis Sentinel para alta disponibilidade
  3. Redis Cluster para fragmentação
  4. Resiliência de conexões no cliente
← Voltar para Redis Caching & Messaging (Pub/Sub, Streams)