1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- require __DIR__.'/shared.php';
- $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
- $pubsub = $client->pubSubLoop();
- $pubsub->subscribe('control_channel', 'notifications');
- foreach ($pubsub as $message) {
- switch ($message->kind) {
- case 'subscribe':
- echo "Subscribed to {$message->channel}", PHP_EOL;
- break;
- case 'message':
- if ($message->channel == 'control_channel') {
- if ($message->payload == 'quit_loop') {
- echo 'Aborting pubsub loop...', PHP_EOL;
- $pubsub->unsubscribe();
- } else {
- echo "Received an unrecognized command: {$message->payload}.", PHP_EOL;
- }
- } else {
- echo "Received the following message from {$message->channel}:",
- PHP_EOL, " {$message->payload}", PHP_EOL, PHP_EOL;
- }
- break;
- }
- }
- unset($pubsub);
- $version = redis_version($client->info());
- echo "Goodbye from Redis $version!", PHP_EOL;
|