使用 Horizon 管理队列,Redis 偶尔报错

Redis 报错: Error while writing bytes to the server

不知道其他人有遇到过没,我都快哭了。

配置如下:

'environments'  =>  [
    'production'  =>  [
        'supervisor-1'  =>  [
            'connection'  =>  'redis',
            'queue'  =>  ['default',  'official_account_sync_0',  'official_account_sync_1',  'official_account_sync_2'],
            'balance'  =>  'auto',
            'processes'  =>  8,
            'tries'  =>  3,
            'memory'  =>  64,
            'timeout'  =>  120
    ]
],

报错如下:

[2019-08-16 10:10:09] production.ERROR: Error while writing bytes to the server. [tcp://127.0.0.1:6379] {"exception":"[object] (Predis\\Connection\\ConnectionException(code: 0): Error while writing bytes to the server. [tcp://127.0.0.1:6379] at /vendor/predis/predis/src/Connection/AbstractConnection.php:155)
[stacktrace]
#0 /vendor/predis/predis/src/Connection/StreamConnection.php(298): Predis\\Connection\\AbstractConnection->onConnectionError('Error while wri...')
#1 /vendor/predis/predis/src/Connection/StreamConnection.php(394): Predis\\Connection\\StreamConnection->write('Wz88m6pCueUZS8Q...')
#2 /vendor/predis/predis/src/Pipeline/Pipeline.php(133): Predis\\Connection\\StreamConnection->writeRequest(Object(Predis\\Command\\HashSetMultiple))
#3 /vendor/predis/predis/src/Pipeline/Pipeline.php(165): Predis\\Pipeline\\Pipeline->executePipeline(Object(Predis\\Connection\\StreamConnection), Object(SplQueue))
#4 /vendor/predis/predis/src/Pipeline/Pipeline.php(214): Predis\\Pipeline\\Pipeline->flushPipeline()
#5 /vendor/predis/predis/src/Client.php(445): Predis\\Pipeline\\Pipeline->execute(Object(Closure))
#6 /vendor/predis/predis/src/Client.php(396): Predis\\Client->createPipeline(NULL, Object(Closure))
#7 /vendor/predis/predis/src/Client.php(418): Predis\\Client->sharedContextFactory('createPipeline', Array)
#8 /vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(114): Predis\\Client->pipeline(Object(Closure))
#9 /vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(214): Illuminate\\Redis\\Connections\\Connection->command('pipeline', Array)
#10 /vendor/laravel/horizon/src/Repositories/RedisJobRepository.php(346): Illuminate\\Redis\\Connections\\Connection->__call('pipeline', Array)
#11 /vendor/laravel/horizon/src/Listeners/MarkJobsAsMigrated.php(36): Laravel\\Horizon\\Repositories\\RedisJobRepository->migrated('redis', 'official_accoun...', Object(Illuminate\\Support\\Collection))
#12 [internal function]: Laravel\\Horizon\\Listeners\\MarkJobsAsMigrated->handle(Object(Laravel\\Horizon\\Events\\JobsMigrated))
#13 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(366): call_user_func_array(Array, Array)
#14 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(196): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Laravel\\\\Horizon...', Array)
#15 /vendor/laravel/horizon/src/RedisQueue.php(155): Illuminate\\Events\\Dispatcher->dispatch('Laravel\\\\Horizon...')
#16 /vendor/laravel/horizon/src/RedisQueue.php(109): Laravel\\Horizon\\RedisQueue->event('official_accoun...', Object(Laravel\\Horizon\\Events\\JobsMigrated))
#17 /vendor/laravel/framework/src/Illuminate/Support/helpers.php(1124): Laravel\\Horizon\\RedisQueue->Laravel\\Horizon\\{closure}(Array)
#18 /vendor/laravel/horizon/src/RedisQueue.php(110): tap(Array, Object(Closure))
#19 /vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php(191): Laravel\\Horizon\\RedisQueue->migrateExpiredJobs('queues:official...', 'queues:official...')
#20 /vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php(167): Illuminate\\Queue\\RedisQueue->migrate('queues:official...')
#21 /vendor/laravel/horizon/src/RedisQueue.php(92): Illuminate\\Queue\\RedisQueue->pop('official_accoun...')
#22 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(251): Laravel\\Horizon\\RedisQueue->pop('official_accoun...')
#23 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(107): Illuminate\\Queue\\Worker->getNextJob(Object(Laravel\\Horizon\\RedisQueue), 'official_accoun...')
#24 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\\Queue\\Worker->daemon('redis', 'official_accoun...', Object(Illuminate\\Queue\\WorkerOptions))
#25 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'official_accoun...')
#26 /vendor/laravel/horizon/src/Console/WorkCommand.php(46): Illuminate\\Queue\\Console\\WorkCommand->handle()
#27 [internal function]: Laravel\\Horizon\\Console\\WorkCommand->handle()
#28 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#29 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#30 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#31 /vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#32 /vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#33 /vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#34 /vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#35 /vendor/symfony/console/Application.php(921): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#36 /vendor/symfony/console/Application.php(273): Symfony\\Component\\Console\\Application->doRunCommand(Object(Laravel\\Horizon\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#37 /vendor/symfony/console/Application.php(149): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#38 /vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#39 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#40 /artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#41 {main}
"} 
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2
4年前 评论
waney (楼主) 4年前

这个错误 应该是redis用的predis, 请在database.php的redis里面,在default数组中添加read_write_timeout=0;

'default' => [
    'url' => env('REDIS_URL'),
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', '6379'),
    'database' => env('REDIS_DB', '0'),
    'read_write_timeout' => 0,
],
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!