sevenlinx/pubsub-redis-php

dev-main / 1.x-dev 2021-04-24 10:10 UTC

This package is auto-updated.

Last update: 2024-03-24 17:01:42 UTC


README

Requirements

Installation

There are two (2) types for Redis client, that needs to install, see Requirements

As soon you have any of the client, you may:

composer require sevenlinx/pubsub-redis-php

Implement your own Redis connector

You may implement your own Redis client decorator, by implementing \SevenLinX\PubSub\Redis\Contracts\ConnectorContract

use SevenLinX\PubSub\Redis\Contracts\ConnectorContract;

class MyOwnConnector implements ConectorContract
{
    ...
    public function publish(ChannelContract $channel, MessageContract $message): int
    {
        return $this->client->publish($channel->name(), $message->payload());
    }

    public function subscribe(ChannelContract|array $channels, Closure $handler): void
    {
        $this->client->subscribe($channels->name(), [$handler, 'handle']);
    }
}

// subscribe.php
$driver = new RedisDriver(new MyOwnConnector());
$driver->subscribe(new GenericChannel(), function(GenericPayload $payload, redis) {
    var_dump($payload);
});

Example

You can check on examples/ directory

/!\ NOTE: This requires an existing redis server /!\

Testing

composer run testing
Created under Seven LinX Incorporated