12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- require_once '../lib/Predis.php';
- $redis = new \Predis\Client('redis://127.0.0.1:6379/?read_write_timeout=-1', 'dev');
- $pubsub = new \Predis\PubSubContext($redis);
- $pubsub->subscribe('control_channel');
- $pubsub->subscribe('notifications');
- foreach ($pubsub as $message) {
- switch ($message->kind) {
- case 'subscribe':
- echo "Subscribed to {$message->channel}\n";
- break;
- case 'message':
- if ($message->channel == 'control_channel') {
- if ($message->payload == 'quit_loop') {
- echo "Aborting pubsub loop...\n";
- $pubsub->unsubscribe();
- }
- else {
- echo "Received an unregognized command: {$message->payload}.\n";
- }
- }
- else {
- echo "Received the following message from {$message->channel}:\n",
- " {$message->payload}\n\n";
- }
- break;
- }
- }
- unset($pubsub);
- $info = $redis->info();
- print_r("Goodbye from Redis v{$info['redis_version']}!\n");
- ?>
|