ostah/laravel-redis-stream

Laravel redis stream

Installs: 53

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 2

pkg:composer/ostah/laravel-redis-stream

1.1.4 2026-02-03 12:55 UTC

This package is auto-updated.

Last update: 2026-02-05 10:16:27 UTC


README

Manage Redis stream messages by firing handler classes per channel. You can assign multiple handler classes to the same channel.

Requirements

  • PHP ^7.4 | ^8.0
  • Laravel / Lumen ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0
  • Redis (phpredis driver recommended)

Installation

Install the package via Composer:

composer require ostah/laravel-redis-stream

Laravel

Publish the config file:

php artisan vendor:publish --tag=laravel-redis-stream-config

Lumen

  1. Register the service provider in bootstrap/app.php:
$app->register(LaravelStream\Redis\StreamServiceProvider::class);
  1. Ensure Redis is registered (add if not already present):
$app->register(Illuminate\Redis\RedisServiceProvider::class);
  1. Copy the config file from vendor/ostah/laravel-redis-stream/config/streaming.php to config/streaming.php.

For more on Redis with Lumen, see the Lumen cache documentation.

Configuration

In config/streaming.php:

  1. Redis connection – Set the connection name under the redis.connection key. This must match a connection defined in config/database.php (e.g. default or a custom stream connection).

  2. Channels and handlers – Define channels and their handler classes:

'channels' => [
    'channel-name' => [
        App\Channels\SomeClassChannel::class,
    ],
],
  1. Trim (optional) – Limit stream length per channel:
'trim' => [
    'channel-name' => 1000, // keep at most 1000 messages
],

We recommend using the phpredis driver for Redis.

Creating a handler class

Generate a channel listener with Artisan (created in app/Channels):

php artisan make:channel-listener SomeClassChannel

Running the channel listener

Listen to all channels:

php artisan stream:run

Listen to a specific channel:

php artisan stream:run --channel=channel-name

Sending messages to a Redis stream

Use the Stream facade to publish messages (xADD):

use LaravelStream\Redis\Facades\Stream;

$messageId = Stream::stream($channel, $data, $trim);
Parameter Type Description
$channel string Channel name
$data mixed Message payload (will be JSON- or msgpack-encoded per config)
$trim int|null Max stream length for this channel. null = use config; 0 = no trimming

License

MIT