iankibet / redis-stream
A Laravel package to listen to Redis published messages.
1.0.3
2025-06-16 07:32 UTC
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
XPENDING
andXCLAIM
to handle stuck messages in production.
๐ License
MIT ยฉ Ian Kibet