簡體   English   中英

Laravel 通過 Redis 排隊:local.ERROR:連接到 127.0.0.1:6379 時出現讀取錯誤

[英]Laravel Queue via Redis: local.ERROR: read error on connection to 127.0.0.1:6379

我試圖通過 redis 連接運行 laravel 隊列,並且在工作人員啟動幾秒鍾后,我收到以下錯誤。

隊列命令:

$> php artisan queue:work --tries=1 --queue=test_queue

錯誤:

local.ERROR: read error on connection to 127.0.0.1:6379 {"exception":"[object] (RedisException(code: 0): read error on connection to 127.0.0.1:6379 at vendor\\laravel\\framework\\src\\Illuminate\\Redis\\Connections\\Connection.php:116)
[stacktrace]
#0 vendor\\laravel\\framework\\src\\Illuminate\\Redis\\Connections\\Connection.php(116): Redis->blPop(Array, 0)
#1 vendor\\laravel\\framework\\src\\Illuminate\\Redis\\Connections\\PhpRedisConnection.php(440): Illuminate\\Redis\\Connections\\Connection->command('blpop', Array)
#2 vendor\\laravel\\framework\\src\\Illuminate\\Redis\\Connections\\PhpRedisConnection.php(179): Illuminate\\Redis\\Connections\\PhpRedisConnection->command('blpop', Array)
#3 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\RedisQueue.php(233): Illuminate\\Redis\\Connections\\PhpRedisConnection->blpop(Array, 0)
#4 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\RedisQueue.php(169): Illuminate\\Queue\\RedisQueue->retrieveNextJob('queues:test_queue')
#5 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(270): Illuminate\\Queue\\RedisQueue->pop('test_queue')
#6 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(123): Illuminate\\Queue\\Worker->getNextJob(Object(Illuminate\\Queue\\RedisQueue), 'test_queue')
#7 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(112): Illuminate\\Queue\\Worker->daemon('redis', 'test_queue', Object(Illuminate\\Queue\\WorkerOptions))
#8 vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'test_queue')
#9 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#10 vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(32): call_user_func_array(Array, Array)
#11 vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(36): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(90): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#13 vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#14 vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#15 vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(201): Illuminate\\Container\\Container->call(Array)
#16 vendor\\symfony\\console\\Command\\Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#17 vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(188): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#18 vendor\\symfony\\console\\Application.php(1012): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 vendor\\symfony\\console\\Application.php(272): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 vendor\\symfony\\console\\Application.php(148): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 {main}
"}

這是隊列配置:

'redis' => [
    'driver' => 'redis',
    'connection' => 'laravel_queues',
    'queue' => env('REDIS_QUEUE', 'default'),
    'retry_after' => 190, 
    'block_for' => 0,
],

這是連接配置:

'laravel_queues' => [
    'host' => env('REDIS_HOST', 'localhost'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', '6379'),
    'database' => 2,
],

編輯 1

Redis 服務器已啟動並運行,其他一切工作正常:

在此處輸入圖像描述

在此處輸入圖像描述


編輯 2

正如建議的那樣,我在 CLI 上運行monitor ,這就是發生的事情:

1596784000.713047 [2 127.0.0.1:62141] "EVAL" "-- Get all of the jobs with an expired \"score\"...\nlocal val = redis.call('zrangebyscore', KEYS[1], '-inf', ARGV[1])\n\n-- If we have values in the array, we will remove them from the first queue\n-- and add them onto the destination queue in chunks of 100, which moves\n-- all of the appropriate jobs onto the destination queue very safely.\nif(next(val) ~= nil) then\n    redis.call('zremrangebyrank', KEYS[1], 0, #val - 1)\n\n    for i = 1, #val, 100 do\n        redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val)))\n        -- Push a notification for every job that was migrated...\n        for j = i, math.min(i+99, #val) do\n            redis.call('rpush', KEYS[3], 1)\n        end\n    end\nend\n\nreturn val" "3" "LOCALHOSTqueues:test_queue:delayed" "LOCALHOSTqueues:test_queue" "LOCALHOSTqueues:test_queue:notify" "1596784000"
1596784000.713180 [2 lua] "zrangebyscore" "LOCALHOSTqueues:test_queue:delayed" "-inf" "1596784000"
1596784000.713362 [2 127.0.0.1:62141] "EVAL" "-- Get all of the jobs with an expired \"score\"...\nlocal val = redis.call('zrangebyscore', KEYS[1], '-inf', ARGV[1])\n\n-- If we have values in the array, we will remove them from the first queue\n-- and add them onto the destination queue in chunks of 100, which moves\n-- all of the appropriate jobs onto the destination queue very safely.\nif(next(val) ~= nil) then\n    redis.call('zremrangebyrank', KEYS[1], 0, #val - 1)\n\n    for i = 1, #val, 100 do\n        redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val)))\n        -- Push a notification for every job that was migrated...\n        for j = i, math.min(i+99, #val) do\n            redis.call('rpush', KEYS[3], 1)\n        end\n    end\nend\n\nreturn val" "3" "LOCALHOSTqueues:test_queue:reserved" "LOCALHOSTqueues:test_queue" "LOCALHOSTqueues:test_queue:notify" "1596784000"
1596784000.713563 [2 lua] "zrangebyscore" "LOCALHOSTqueues:test_queue:reserved" "-inf" "1596784000"
1596784000.713972 [2 127.0.0.1:62141] "EVAL" "-- Pop the first job off of the queue...\nlocal job = redis.call('lpop', KEYS[1])\nlocal reserved = false\n\nif(job ~= false) then\n    -- Increment the attempt count and place job on the reserved queue...\n    reserved = cjson.decode(job)\n    reserved['attempts'] = reserved['attempts'] + 1\n    reserved = cjson.encode(reserved)\n    redis.call('zadd', KEYS[2], ARGV[1], reserved)\n    redis.call('lpop', KEYS[3])\nend\n\nreturn {job, reserved}" "3" "LOCALHOSTqueues:test_queue" "LOCALHOSTqueues:test_queue:reserved" "LOCALHOSTqueues:test_queue:notify" "1596784190"
1596784000.714130 [2 lua] "lpop" "LOCALHOSTqueues:test_queue"
1596784000.714340 [2 127.0.0.1:62141] "BLPOP" "LOCALHOSTqueues:test_queue:notify" "0"

我有一個 WebApp 應用程序連接到 Redis docker 並遇到了類似的問題。 這是我學到的:

我推薦使用 docker-compose(強烈推薦)它幫助解決了我的許多問題。 redis docker 的主機名將是 redis 容器的服務名稱 - 請參見下面的“#”

   version: '3.9'
     services:
       php-service:
         image: <your-php-image>

         ports:
           - "8000:8000"
         depends_on:
           - redis
         expose:
           - "8000"

      redis:  # this is going to be the hostname of redis for you php-service
        image: <your-redis-image>
        ports:
          - "6379:6379"
        sysctls:
          net.core.somaxconn: '511'

要從 PHP-WebApp docker 中引用到 redis 主機的連接,請將主機名更改為

 redis://redis:6379/0 # notice the /0 after the port - I couldn't make it work without this -- also notice that the second redis (which is the host name - the first is the protocol name) matches the name of the service in docker-compose

If the PHP webapp is running on your local machine outside of a docker container while trying to connect to redis running inside a docker container, change the redis host name to

redis://localhost:6379/0 # notice the /0 is still necessary but instead of the service name inside of docker-compose being used as the host, localhost is used

祝你好運並評論你有任何問題 - 我想我可以提供幫助。

這是使用PHPRedis的一個很大的缺點,想知道Laravel開發人員是否知道這一點,因為 Predis 已被棄用以支持PHPRedis

這里的建議是使用Supervisor ,因為它將解決此問題和任何其他意外的連接丟失問題,並確保偵聽器始終在運行,幾乎不會停機。

命令的keep-alive選項應減輕此連接超時錯誤並立即重新開始偵聽。 也許這會對你有所幫助。

詳細解釋請參考PHPRedis

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM