equip / redis-queue
该软件包已被弃用且不再维护。未建议替代软件包。
用于将 Redis 作为作业队列的小型库
0.1.0
2016-01-08 21:23 UTC
Requires
- aura/cli: ^2
- equip/command: ^1
- equip/framework: ^1
- predis/predis: ^1
Requires (Dev)
- phake/phake: ^2
- phpunit/phpunit: ^4
This package is auto-updated.
Last update: 2021-07-31 01:37:29 UTC
README
这是一个用于在 Equip 应用程序中将 Redis 作为作业队列使用的小型库。
安装
使用 Composer。
composer require equip/redis-queue
添加 DefaultConfigurationSet
配置到您的项目中。
消费
消费者是用 equip/command 编写的命令。有关更多信息,请参阅其文档。
要运行消费者,请使用此存储库中包含的示例 运行器。此运行器使用两个环境变量 REDIS_HOST
和 REDIS_PORT
来指向要使用的 Redis 服务器;默认分别为 '127.0.0.1'
和 6379
。运行器接受一个必需的参数:表示消费者从其中检索作业的 Redis 键的 Redis 键。
REDIS_HOST=example.com REDIS_PORT=12345 ./bin/consume queue_name
请注意,您的运行器需要配置您的 Auryn Injector
实例,以便它能够创建您的消费者命令类及其依赖项的实例。
发布
作业是通过 Publisher
类的实例发布的。在 DefaultConfigurationSet
中包含的配置应该足够由 Auryn 生成其实例。
以下是从领域类发布作业的示例,其中 Acme\Command\FooCommand
是一个旨在作为消费者的命令类。
namespace Acme; use Acme\Command\FooCommand; use Equip\Adr\DomainInterface; use Equip\RedisQueue\Publisher; class FooDomain implements DomainInterface { private $publisher; public function __construct(Publisher $publisher) { $this->publisher = $publisher; } public function __invoke(array $input) { // ... $command_options = ['foo' => 'bar']; $this->publisher->publish( 'queue_name', FooCommand::class, $command_options ); } }
要发布作业,请使用这些参数调用 Publisher
实例的 publish()
方法
- 第一个参数是包含队列名称的字符串,该名称必须是一个有效的 Redis 键
- 第二个参数是包含执行作业逻辑的命令类的完全限定名称
- 第三个参数是一个关联数组,包含用于命令类实例的选项