<?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';
$loop = new React\EventLoop\StreamSelectLoop();
$consumer = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$producer = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$consumer->connect(function ($consumer) use($producer) {
    echo "Connected to Redis, will BLPOP for max 10 seconds on `nrk:queue` and produce an item in ~5 seconds.\n";
    $start = microtime(true);
    $consumer->blpop('nrk:queue', 10, function ($response) use($consumer, $producer, $start) {
        list($queue, $stop) = $response;
        $seconds = round((double) $stop - $start, 3);
        echo "Received item from `{$queue}` after {$seconds} seconds!\n";
        $consumer->disconnect();
        $producer->disconnect();
    });
    $consumer->getEventLoop()->addTimer(5, function () use($producer) {
        $producer->lpush('nrk:queue', $microtime = microtime(true), function () use($microtime) {
            echo "Just pushed {$microtime} to `nrk:queue`.\n";
        });
    });
});
$loop->run();
Beispiel #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!\n";
    $tx = $client->transaction();
    $tx->ping();
    $tx->echo("FOO");
    $tx->echo("BAR");
    $tx->execute(function ($replies, $client) {
        var_dump($replies);
        $client->info('cpu', function ($cpuInfo, $client) {
            var_dump($cpuInfo);
            $client->disconnect();
        });
    });
});
$client->getEventLoop()->run();
Beispiel #3
0
<?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();