dweik/laravel-redis-stream
Composer 安装命令:
composer require dweik/laravel-redis-stream
包简介
Laravel redis stream
README 文档
README
This package using to manage the Redis stream messages listener by firing handler classes based on the defined channels. in this package, you could assign multiple classes to the same channel.
Installation
Require this package with composer using the following command:
composer require dweik/laravel-redis-stream
Laravel
Then you need to publish the config files by executing the following command
php artisan vendor:publish --tag=laravel-redis-stream-config
lumen
You need to add the follow line on bootstrap/app.php file:
$app->register(LaravelStream\Redis\StreamServiceProvider::class);
and make sure that you loaded Redis by add the follow line (if exists no need to add)
$app->register(Illuminate\Redis\RedisServiceProvider::class);
NOTE if you need more information to how setup redis on lumen you can check the official website by a click here
Then you need to copy the streaming config file from vendor/dweik/laravel-redis-stream/config/streaming.php to
config/streaming.php
On config/streaming.php file, you need to set up the Redis connection under the redis key.
then you need to define the names of the channels by assigning handler classes as below example:
- note: We prefer use phpredis driver.
'channels' => [ 'channel-name' => [ App\Channels\SomeClassChannel::class ], ],
Also, you could define the trimming value for each channel under trim key. Ex.,
'trim' => [ 'channel-name' => 1000, // it means keep 1000 messages at most ],
Creating handler class
Use artisan command to make a new handler class by using the make:channel-listener function.
then you can find it on the app/Channels path
php artisan make:channel-listener SomeClassChannel
Run channel listener
To run channel listener for all channels use the following command
php artisan stream:run
To run a specific channel you could pass to the --channel option the channel name like :_
php artisan stream:run --channel=channel-name
Send a message to Redis stream
There is a facade class that could handle the xADD command on redis
use LaravelStream\Redis\Facades\Stream; class SomeClass { public function(){ /* . . some code . */ /** * * @var string $channel channel name * @var mixed $data the message data * @var integer $trim (default null) the channel messages size, * when using (null) value, this package will use * the defined value on the config file "config/streaming.php". * when using (zero) value that means stop trimming function */ $messageID = Stream::stream( $channel, $data, $trim); } }
dweik/laravel-redis-stream 适用场景与选型建议
dweik/laravel-redis-stream 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.99k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「stream」 「command」 「laravel」 「artisan」 「Microservice」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dweik/laravel-redis-stream 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dweik/laravel-redis-stream 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dweik/laravel-redis-stream 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Microservice RPC through message queues.
Object-Oriented API for PHP streams
Shell command module for PHP.
The CodeIgniter Redis package
统计信息
- 总下载量: 10.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-06