12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- require __DIR__.'/shared.php';
- $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
- $pubsub = $client->pubSubLoop();
- $dispatcher = new Predis\PubSub\DispatcherLoop($pubsub);
- class EventsListener implements Countable
- {
- private $events;
- public function __construct()
- {
- $this->events = array();
- }
- public function count()
- {
- return count($this->events);
- }
- public function getEvents()
- {
- return $this->events;
- }
- public function __invoke($payload, $dispatcher)
- {
- $this->events[] = $payload;
- }
- }
- $dispatcher->attachCallback('events', ($events = new EventsListener()));
- $dispatcher->attachCallback('control', function ($payload, $dispatcher) {
- if ($payload === 'terminate_dispatcher') {
- $dispatcher->stop();
- }
- });
- $dispatcher->run();
- echo "We received {$events->count()} messages!", PHP_EOL;
- $version = redis_version($client->info());
- echo "Goodbye from Redis $version!", PHP_EOL;
|