123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- require 'SharedConfigurations.php';
- $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
- $dispatcher = new Predis\PubSub\DispatcherLoop($client);
- 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)
- {
- $this->events[] = $payload;
- }
- }
- $dispatcher->attachCallback('events', ($events = new EventsListener()));
- $dispatcher->attachCallback('control', function ($payload) use ($dispatcher) {
- if ($payload === 'terminate_dispatcher') {
- $dispatcher->stop();
- }
- });
- $dispatcher->run();
- echo "We received {$events->count()} messages!\n";
- $info = $client->info();
- print_r("Goodbye from Redis v{$info['redis_version']}!\n");
|