PHPackages                             andreagroferreira/redis-stream - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. andreagroferreira/redis-stream

ActiveLibrary[Caching](/categories/caching)

andreagroferreira/redis-stream
==============================

A powerful, reliable Redis Streams implementation for Laravel applications

1.0.0(1y ago)7231[1 PRs](https://github.com/andreagroferreira/laravel-redis-stream/pulls)MITPHPPHP ^8.1|^8.2|^8.3|^8.4CI passing

Since Mar 12Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/andreagroferreira/laravel-redis-stream)[ Packagist](https://packagist.org/packages/andreagroferreira/redis-stream)[ Docs](https://github.com/andreagroferreira/laravel-redis-stream)[ RSS](/packages/andreagroferreira-redis-stream/feed)WikiDiscussions v1.0.0 Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (8)Used By (0)

Redis Stream Package for Laravel
================================

[](#redis-stream-package-for-laravel)

A powerful, reliable Redis Streams implementation for Laravel applications. This package makes it easy to work with Redis Streams for event-driven applications, message processing, and real-time data pipelines.

[![Latest Version on Packagist](https://camo.githubusercontent.com/931cdade40dbb6065468bbf29a1f5e60d7e2d3d3d26bda679427b75f45aa3368/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e6472656167726f66657272656972612f72656469732d73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreagroferreira/redis-stream)[![Total Downloads](https://camo.githubusercontent.com/37c4c7c7275ca9b361ad039abba793f59bf8e0ae9567aa6a5a79caeec15c87fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6472656167726f66657272656972612f72656469732d73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreagroferreira/redis-stream)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Version Support](https://camo.githubusercontent.com/3df15037bdd4b5d09ab4724c04ff4d67adb2c6e9cc1dfedf3e40710d18394780/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616e6472656167726f66657272656972612f72656469732d73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreagroferreira/redis-stream)[![Laravel Version Support](https://camo.githubusercontent.com/a654fdf1fbc7e288fc61ec9595f9dc36a153cb3bc4d4750a36b42665b0b2ac8b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e7825323025374325323031302e7825323025374325323031322e782d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreagroferreira/redis-stream)[![GitHub forks](https://camo.githubusercontent.com/7377e59dba05ce908780286f74040ea2b33e6e894b7456a3ead44b153dd54640/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f616e6472656167726f66657272656972612f6c61726176656c2d72656469732d73747265616d2e7376673f7374796c653d736f6369616c266c6162656c3d466f726b266d61784167653d32353932303030)](https://github.com/andreagroferreira/laravel-redis-stream)[![GitHub stars](https://camo.githubusercontent.com/5bd86fa74a171cbb91e50a38c95059e6e314e05b3602f87f3522073ef4fb2d90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f616e6472656167726f66657272656972612f6c61726176656c2d72656469732d73747265616d2e7376673f7374796c653d736f6369616c266c6162656c3d53746172266d61784167653d32353932303030)](https://github.com/andreagroferreira/laravel-redis-stream)

Features
--------

[](#features)

- ✅ Proper exception handling with typed exceptions
- 🚀 Simple producer/consumer API for Redis Streams
- ♻️ Compatible with both phpredis and predis drivers
- 🔄 Automatic consumer group management
- 🔁 Retry handling for failed messages
- 📊 Batch publishing support for high-throughput applications
- 🛑 Graceful shutdown support
- ⚙️ Configurable stream trimming (MAXLEN)
- 📟 Built-in Artisan command for consuming streams

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require andreagroferreira/redis-stream
```

### Redis Driver Requirements

[](#redis-driver-requirements)

This package supports both `phpredis` (the PHP extension) and `predis` (PHP library) drivers:

**For PHP Redis Extension (recommended for production):**

```
# Install the PHP Redis Extension
pecl install redis
# Add "extension=redis.so" to your php.ini
```

**For Predis Library:**

```
# Install Predis library
composer require predis/predis
```

The package will automatically detect which driver you're using.

After installation, publish the configuration file:

```
php artisan vendor:publish --provider="WizardingCode\RedisStream\RedisStreamServiceProvider"
```

Configuration
-------------

[](#configuration)

Configure your Redis connection for streams in your `.env` file:

```
REDIS_STREAM_CONNECTION=streams
REDIS_STREAM_NAME=default_stream
REDIS_STREAM_CONSUMER_GROUP=default_group
REDIS_STREAM_CONSUMER_NAME=default_consumer
REDIS_STREAM_MAX_LENGTH=1000000
REDIS_STREAM_POLL_INTERVAL=1
REDIS_STREAM_RETRY_LIMIT=3
REDIS_STREAM_BATCH_SIZE=10

```

You can also define custom streams in the `redis_stream.php` config file.

Usage
-----

[](#usage)

### Exception Handling

[](#exception-handling)

This package provides specific exception types for better error handling:

- `RedisStreamException`: Base exception class for all Redis Stream errors
- `ConnectionException`: Thrown when Redis connection fails
- `PublishException`: Thrown when message publishing fails
- `ConsumeException`: Thrown when message consumption fails
- `MessageProcessingException`: Thrown when message processing fails

Example of handling exceptions:

```
use WizardingCode\RedisStream\Exceptions\ConnectionException;
use WizardingCode\RedisStream\Exceptions\PublishException;

try {
    $producer->publish('user.created', $userData);
} catch (ConnectionException $e) {
    // Handle connection issues
    Log::error("Redis connection error: " . $e->getMessage());
    // Maybe retry or queue for later
} catch (PublishException $e) {
    // Handle publishing issues
    Log::error("Failed to publish message: " . $e->getMessage());
} catch (Exception $e) {
    // Handle other errors
    Log::error("Unexpected error: " . $e->getMessage());
}
```

### Basic Example

[](#basic-example)

```
