halaei / bredis
Long polling (blocking pop) for Redis queue driver in Laravel
Installs: 4 194
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 2
Requires
- php: >=7.0.0
- illuminate/queue: >=5.5
- illuminate/redis: >=5.5
- predis/predis: ~1.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2022-02-01 13:01:33 UTC
README
When do you need bredis?
You need bredis
when all of these are applied:
- You don't want your jobs to be delayed because your workers are currently sleeping.
- You don't want to run
queue:work --sleep=0
on current Redis queue driver because it will devour your CPU when there is no job.
Hence, you need your workers to idle-wait for a job and process them just when they arrive, with nearly no delay.
With bredis
you can happily run queue:work --sleep=0
without worrying about busy waiting and CPU overload.
Installation
1. Install the package via compioser
composer require halaei/bredis
2. Add the service provider to your config/app.php
Halaei\BRedis\BlockingRedisServiceProvider::class
3. Add bredis connections to app/queue.php
'bredis' => [
'driver' => 'bredis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
'timeout' => 10, //Maximum seconds to wait for a job
],
Please note that if you need to increase 'timeout' in the config array above, you should increase 'retry_after' in the array as well as --timeout in your queue:work
commands.
Warning: bredis queue workers don't bother handling jobs that are delayed or reserved. So when using bredis workers, you have to have at least one redis worker as well.
Note: bredis queue driver is 100% compatible with redis driver. In other words, you may push the jobs using redis driver and pop them using bredis, or vice versa.