sevenlinx / pubsub-redis-php
PubSub中的Redis驱动
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-09-24 18:01:50 UTC
README
要求
- PHP
^8.0
- ext-phpredis - 用于Redis扩展和
PhpRedisConnector
(推荐) - predis/predis - 用于
PredisConnector
安装
需要安装两种Redis客户端,详情请见要求
- ext-phpredis - PHP扩展用于Redis,需要构建PHP
- predis/predis - 纯PHP客户端用于Redis
一旦您拥有任何客户端,您可以
composer require sevenlinx/pubsub-redis-php
实现自己的Redis连接器
您可以通过实现 \SevenLinX\PubSub\Redis\Contracts\ConnectorContract
来实现自己的Redis客户端装饰器
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); });
示例
您可以在examples/
目录中查看
/!\ 注意:此要求已存在的redis服务器 /!\
测试
composer run testing