andrzejkupczyk/redis-messenger

This package is abandoned and no longer maintained. No replacement package was suggested.

Framework-agnostic Redis Streams client

dev-master / 1.0.x-dev 2020-11-25 10:42 UTC

This package is auto-updated.

Last update: 2021-09-25 12:42:44 UTC


README

PHP requirement Code quality

Framework-agnostic Redis Streams client.

Examples of use

This package aims to support all Redis Streams commands that are available. Examples listed below illustrates only the simplest use cases, but more examples are provided.

Publishing messages

use WebGarden\Messaging\Client;
use WebGarden\Messaging\Redis\{Entry,Stream};

$client = Client::connect('redis');

$client
    ->to(new Stream('mystream'))
    ->add(
        Entry::compose(['name' => 'Sara', 'surname' => 'OConnor']),
        Entry::compose(['field1' => 'value1', 'field2' => 'value2'])
    );

Consuming messages

use WebGarden\Messaging\Client;
use WebGarden\Messaging\Redis\Stream;
use WebGarden\Messaging\Events\ItemReceived;

$client = Client::connect('redis');

$client
    ->from(new Stream('mystream'))
    ->on('reader.item_received', function (ItemReceived $event) {
        printf("Received item %s\n", $event->entry->id());
    })
    ->followNewEntries();

Install

Via Composer

composer require andrzejkupczyk/redis-messenger

ℹ️️ package requires the PhpRedis PHP extension