iankibet/redis-stream

A Laravel package to listen to Redis published messages.

1.0.3 2025-06-16 07:32 UTC

This package is auto-updated.

Last update: 2025-06-16 07:33:03 UTC


README

Latest Stable Version Total Downloads License

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 and XCLAIM to handle stuck messages in production.

๐Ÿ“„ License

MIT ยฉ Ian Kibet