superbalist / php-pubsub-redis
此包已被弃用且不再维护。未建议替代包。
php-pubsub包的Redis适配器
2.0.0
2017-05-16 11:26 UTC
Requires
- php: >=5.6.0
- predis/predis: ^0.8|^1.0|^1.1
- superbalist/php-pubsub: ^2.0
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^5.5
This package is auto-updated.
Last update: 2024-08-12 00:18:14 UTC
README
php-pubsub包的php-pubsub适配器。
安装
composer require superbalist/php-pubsub-redis
使用
$client = new Predis\Client([ 'scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379, 'database' => 0, 'read_write_timeout' => 0 ]); $adapter = new \Superbalist\PubSub\Redis\RedisPubSubAdapter($client); // consume messages // note: this is a blocking call $adapter->subscribe('my_channel', function ($message) { var_dump($message); }); // publish messages $adapter->publish('my_channel', 'HELLO WORLD'); $adapter->publish('my_channel', ['hello' => 'world']); $adapter->publish('my_channel', 1); $adapter->publish('my_channel', false); // publish multiple messages $messages = [ 'message 1', 'message 2', ]; $adapter->publishBatch('my_channel', $messages);
示例
该库包含了适配器的示例以及运行示例脚本的Dockerfile。
运行 make up
。
您将进入 /opt/php-pubsub
目录下的 bash
提示符。
如果您需要另一个shell来向阻塞消费者发布消息,您可以运行 docker-compose run php-pubsub-redis /bin/bash
运行示例
$ php examples/RedisConsumerExample.php $ php examples/RedisPublishExample.php (in a separate shell)