最近加了一台服务器,使用两台服务器部署nginx的负载均衡,但是运行了一段时间后,Redis报错:Error while reading line from the server


解决方案:

  1. 修改 config/database.php 文件,找到 redis 的配置项,加上 read_write_timeout 参数,设置为 0来禁用 Redis 的默认超时。
'redis' => [
        'cluster' => false,
        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
            'read_write_timeout' => 0
        ],
],

  1. 如果第一种方案行不通的话,而此时你的项目只有某台 redis 出现 Error while reading line from the server 的问题时,你可能需要检查一下该 redis 的配置,设置 timeout 为较大的数值或者关闭(不推荐关闭)
timeout=10
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐