iankibet/redis-stream
最新稳定版本:1.0.3
Composer 安装命令:
composer require iankibet/redis-stream
包简介
A Laravel package to listen to Redis published messages.
README 文档
README
A Laravel package to use Redis Streams for lightweight, scalable inter-service communication or job/event dispatching.
🚀 Features
- Simple Redis Streams integration
- Stream-to-handler mapping via config
- Supports multiple consumers under the same group
- Automatically dispatches Jobs or Events
- Clean CLI command with optional consumer override
🛠 Installation
composer require iankibet/redis-stream
Publish the config:
php artisan vendor:publish --tag=redis-stream
⚙️ Configuration
Edit the generated config file at config/redis-stream.php:
return [ 'group' => env('REDIS_STREAM_GROUP', env('APP_NAME', 'laravel')), 'consumer' => env('REDIS_STREAM_CONSUMER', env('REDIS_STREAM_GROUP', env('APP_NAME', 'laravel'))), 'handlers' => [ 'user_activity' => [ App\Jobs\ProcessUserActivity::class, ], 'order_events' => [ App\Events\OrderCreated::class, ], ], ];
📥 Publishing to a Stream
You can publish messages using the RedisStream facade:
use Iankibet\RedisStream\RedisStream; RedisStream::publish('order_events', [ 'order_id' => 123, 'status' => 'created', ]);
🧑💻 Consuming Messages
Run the consumer using:
php artisan redis:consume-stream
Or provide a specific consumer name:
php artisan redis:consume-stream worker-1
Messages are read from all streams defined in the config and dispatched automatically to jobs or events.
🧪 Testing
Run the tests:
php artisan test
🧠 Notes
- Each message is delivered to only one consumer in a group.
- Redis automatically tracks pending/unacknowledged messages.
- You should monitor or use
XPENDINGandXCLAIMto handle stuck messages in production.
📄 License
MIT © Ian Kibet
统计信息
- 总下载量: 1.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-16