Download the PHP package bhamner/laravel-redis-streams without Composer
On this page you can find all versions of the php package bhamner/laravel-redis-streams. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bhamner/laravel-redis-streams
More information about bhamner/laravel-redis-streams
Files in bhamner/laravel-redis-streams
Package laravel-redis-streams
Short Description Eloquent- and queue-style API for Redis Streams consumer groups.
License MIT
Informations about the package laravel-redis-streams
Laravel Redis Streams
A Composer package for Redis Streams consumer groups. create() appends an entry. A group delivers each new entry to one consumer, and the entry stays pending until that consumer calls ack().
Laravel's Redis connection already forwards the raw commands (XADD, XREADGROUP, XACK, XAUTOCLAIM, and the rest). This package is the fluent layer on top of them. It works with both the PhpRedis extension and Predis, and it keeps your configured Redis key prefix.
Install
The package is on Packagist.
Laravel discovers the service provider. Publish the config if you want to change the connection or worker defaults:
The package uses the Redis connection named in REDIS_STREAM_CONNECTION (default when unset).
Append entries
A stream class sets the Redis key:
add() accepts maxLength when the stream should be trimmed as it grows:
Typed events
dispatch() stores the class name and its public properties on the stream:
Consumer groups
Each new entry is delivered to one consumer in the group. It stays in the pending list until ack(). Another consumer can claim it with claimIdle() after the idle time has passed.
pop() and read() create the group the first time (XGROUP CREATE ... MKSTREAM), starting at $ so only new entries are delivered. Pass ensure('0') when this group should start from the beginning of the stream.
Pending work and idle claims:
A worker
Extend Consumer and run it with redis-streams:work. The command claims entries that have been pending longer than claim_after, reads new ones, calls handle, and acknowledges on success. An exception leaves the entry pending. After max_deliveries (default 5) the worker calls failed() and acknowledges the entry.
SIGTERM and SIGINT stop the loop when the pcntl extension is loaded.
Defaults
| Config | Env | Default |
|---|---|---|
connection |
REDIS_STREAM_CONNECTION |
default |
block |
REDIS_STREAM_BLOCK |
2000 milliseconds |
count |
REDIS_STREAM_COUNT |
10 |
claim_after |
REDIS_STREAM_CLAIM_AFTER |
60000 milliseconds |
max_deliveries |
REDIS_STREAM_MAX_DELIVERIES |
5 |
Override any of those on the consumer class with $block, $count, $claimAfter, $maxDeliveries, or $start.
Contributing
Bug reports and pull requests are welcome on GitHub.
Open an issue for a bug. Include the Laravel and Redis versions, whether you use PhpRedis or Predis, and the smallest snippet that shows the failure.
To send a change:
- Fork the repository and create a branch.
- Add or update a test when the change affects behavior.
- Run
vendor/bin/phpunit. The suite needs PHP 8.2 or newer. - Open a pull request against
mainand describe what the change does.
All versions of laravel-redis-streams with dependencies
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/redis Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0