<?php /* * This file is part of the Predis\Async package. * * (c) Daniele Alessandri <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/../autoload.php'; $client = new Predis\Async\Client('tcp://127.0.0.1:6379'); $client->connect(function ($client) { echo "Connected to Redis, now listening for incoming messages...\n"; $client->pubsub('nrk:channel', function ($event, $pubsub) { $message = "Received message `%s` from channel `%s` [type: %s].\n"; $feedback = sprintf($message, $event->payload, $event->channel, $event->kind); echo $feedback; if ($event->payload === 'quit') { $pubsub->quit(); } }); }); $client->getEventLoop()->run();
<?php require 'vendor/autoload.php'; $client = new Predis\Async\Client('tcp://colin.dev.shazamteam.net:6370'); $client->connect(function ($client) { echo "Connected to Redis, now listening for incoming messages...\n"; $logger = new Predis\Async\Client('tcp://127.0.0.1:6379', $client->getEventLoop()); $client->pubsub('tags', function ($event) use($logger) { $tag = json_decode($event->payload); $title = $tag->{'match'}->{'track'}->{'metadata'}->{'trackTitle'}; $artist = $tag->{'match'}->{'track'}->{'metadata'}->{'artistName'}; echo "Tagged `{$title}` by {$artist}\n"; }); }); $client->getEventLoop()->run();