sevenlinx / pubsub-redis-php
Redis driver in PubSub
dev-main / 1.x-dev
2021-04-24 10:10 UTC
Requires
- php: ^8.0
- sevenlinx/pubsub-php: 1.x-dev
Requires (Dev)
- mockery/mockery: ^1.4
- phpstan/phpstan: ^0.12
- phpstan/phpstan-mockery: ^0.12
- phpunit/phpunit: ^9.5
Suggests
- ext-redis: Required to use the PHPRedis client (^4.0|^5.0).
- predis/predis: Required to use the predis client (^1.1).
This package is auto-updated.
Last update: 2024-10-24 18:10:50 UTC
README
Requirements
- PHP
^8.0
- ext-phpredis - For Redis extension and
PhpRedisConnector
(RECOMMENDED) - predis/predis - For
PredisConnector
Installation
There are two (2) types for Redis client, that needs to install, see Requirements
- ext-phpredis - PHP Extension for Redis, need to build PHP
- predis/predis - Pure PHP client for Redis
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