laravie / streaming
Redis Async Streaming for PHP
Fund package maintenance!
Liberapay
paypal.me/crynobone
Installs: 16 261
Dependents: 0
Suggesters: 0
Security: 0
Stars: 25
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=7.2
- laravie/predis-async: ^0.3 || ^0.4
Requires (Dev)
- phpunit/phpunit: ^8.4 || ^9.0
README
The project allows you as a developer to listen to Redis pubsub using async instead of blocking I/O using PHP. This is done by utilizing predis/predis-async
under the hood.
Installation
To install through composer, simply put the following in your composer.json
file:
{ "require": { "laravie/streaming": "^3.0" } }
And then run composer install
from the terminal.
Quick Installation
Above installation can also be simplify by using the following command:
composer require "laravie/streaming=^3.0"
Example
<?php $eventLoop = React\EventLoop\Factory::create(); $chat = new class implements Laravie\Streaming\Listener { /** * @return array<int, string> */ public function subscribedChannels(): array { return ['topic:*']; } /** * @param \Predis\Async\Client $redis * @return void */ public function onConnected($redis) { echo "Connected to redis!"; } /** * @param \Predis\Async\Client $redis * @return void */ public function onSubscribed($redis) { echo "Subscribed to channel `topic:*`!"; } /** * Trigger on emitted listener. * * @param object $event * @param object $pubsub * * @return void */ public function onEmitted($event, $pubsub) { // PUBLISH topic:laravel "Hello world" # DESCRIBE $event # # { # "kind": "pmessage", # "pattern": "topic:*", # "channel": "topic:laravel", # "payload": "Hello world" # } } } $client = new Laravie\Streaming\Client( ['host' => '127.0.0.1', 'port' => 6379], $eventLoop ); $client->connect($chat); $eventLoop->run();