# redis.exceptions.MasterDownError：错误：主节点已关闭或无法访问

- **ID:** `database/redis-master-link-down`
- **领域:** database
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Redis 客户端无法连接到复制设置中的主节点，通常由于网络分区、主节点崩溃或 replicaof 指令配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Redis 6.2.x | active | — | — |
| Redis 7.0.x | active | — | — |
| Redis 7.2.x | active | — | — |

## 解决方案

1. ```
   从副本检查主节点状态：redis-cli -h replica_host INFO replication | grep master_link_status；如果为 down，检查主节点：redis-cli -h master_host PING；如果需要，重启主节点：systemctl restart redis-server
   ```
2. ```
   在故障转移场景中将副本提升为主节点：redis-cli -h replica_host SLAVEOF NO ONE；然后重新配置其他副本指向新主节点。
   ```

## 无效尝试

- **Restarting only the replica node** — If the master is down, restarting the replica does not fix the connection; the replica will still fail to sync. (90% 失败率)
- **Increasing replica timeout in redis.conf without checking master health** — Increasing timeout only delays the error; it does not address the root cause of master unavailability. (70% 失败率)
