handcraftedinthealps / redis-transport-bundle
Redis流的消息传输实现。
1.2.1
2024-01-17 13:52 UTC
Requires
- php: ^7.3 || ^8.0
- ext-redis: ^4.2 || ^5.0 || ^6.0
- symfony/config: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/dependency-injection: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/messenger: ^4.3 || ^5.4 || ^6.0
- symfony/property-access: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/serializer: ^3.4 || ^4.0 || ^5.4 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0 || ^3.9
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.8
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^9.5
- symfony/console: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/error-handler: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/framework-bundle: ^3.4 || ^4.0 || ^5.4 || ^6.0
- symfony/redis-messenger: ^5.4 || ^6.0
- symfony/yaml: ^3.4 || ^4.0 || ^5.4 || ^6.0
Suggests
- symfony/redis-messenger: Required if version of symfony/messenger is >= 5.1
README
Redis流的消息传输实现。
注意:大部分逻辑已转移到4.3版本的Core Symfony Messenger组件中。因此,此包不再是使用Redis流与messenger配合的必需品。现在你可以使用
redis://
而不是redis-stream://
,并从要求中移除此包。
要求
- PHP:
^7.1
- Redis扩展:
^4.2
- Redis扩展:
- Redis服务器:
^5.0
Symfony兼容性
当升级到symfony 4.3时,你应该用symfony的redis://
传输替换此包,并从要求中移除该包。
安装
你需要composer来将此包安装到你的symfony应用程序中。
composer require handcraftedinthealps/redis-transport-bundle
配置
Symfony
当使用symfony/framework-bundle时,你可以配置以下内容
# config/packages/framework.yaml framework: messenger: routing: 'HandcraftedInTheAlps\Bundle\RedisTransportBundle\Message\DomainEventMessage': senders: ['redis_stream'] transports: redis_stream: 'redis-stream://127.0.0.1:6379/my_stream/my_group/my_consumer'
然后你可以在Redis流中发送DomainEventMessage或自定义Message
use HandcraftedInTheAlps\Bundle\RedisTransportBundle\Message\DomainEventMessage; $this->messageBus->dispatch( new DomainEventMessage( 'mountain.modified', // the custom event action 'mountain', // the model which has been changed '1', // the model id or uuid [ // the model payload 'id' => '1', 'name' => 'Piz Buin', 'height' => 3312, ] ) );
你也可以使用以下方式消费消息
bin/console messenger:consume-messages redis_stream
请参阅messenger组件文档和messenger使用文档。
命令
默认情况下,流中的消息不会被删除。因此,此包提供了一个命令
bin/console redis-transport:trim <redis-dsn> --maxlen 1000