12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- require 'SharedConfigurations.php';
- $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
- $dispatcher = new Predis\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");
|