# RedisException：连接到 127.0.0.1:6379 时读取错误，位于 /var/www/app/src/Cache/RedisCache.php 第 15 行

- **ID:** `php/redis-connection-read-error`
- **领域:** php
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Redis 服务器突然关闭了连接，通常是由于超时设置、内存压力或网络不稳定。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |
| Redis 6.2 | active | — | — |
| Redis 7.0 | active | — | — |

## 解决方案

1. ```
   Increase the Redis server's timeout setting (timeout 0) in redis.conf to prevent idle connections from being closed.
   ```
2. ```
   Implement a retry mechanism in PHP with exponential backoff when a RedisException is caught.
   ```

## 无效尝试

- **** — Increasing PHP's default_socket_timeout in php.ini does not affect Redis socket timeouts, which are handled separately. (90% 失败率)
- **** — Restarting only PHP-FPM without restarting Redis may not help if the Redis server itself is overloaded or has a high memory usage. (75% 失败率)
- **** — Disabling persistence (redis.persistent) may reduce the frequency but does not address the root cause of connection drops. (65% 失败率)
