Exemplo n.º 1
0
 public function __construct($loop)
 {
     $redis_host = config('database.redis.default.host');
     $redis_port = config('database.redis.default.port');
     $client = new \Predis\Async\Client('tcp://' . $redis_host . ':' . $redis_port, $loop);
     $client->connect(function ($client) use($loop) {
         // $logger = new \Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
         $logger = null;
         $client->pubSubLoop('WampMessage', function ($event) use($logger) {
             $payload = json_decode($event->payload, true);
             Chat::getInstance()->broadcast($payload['data']);
         });
         Log::v(' ', $loop, "Connected to Redis.");
     });
 }
Exemplo n.º 2
0
<?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->pubSubLoop('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();