예제 #1
0
 private function onConnect(Client $client)
 {
     echo "Connected to Redis, now listening for incoming messages...\n";
     $client->pubSubLoop('test:channel', function ($event) {
         $this->onMessage($event);
     });
 }
예제 #2
0
 private function saveGarbage(PredisClient $redis, $data)
 {
     $deferred = new Deferred();
     $tx = $redis->multiExec();
     $tx->incr('garbage-counter');
     $tx->execute(function ($replies, $redis) use($deferred, $data) {
         $hashId = 'garbage-' . $replies[0];
         $redis->set($hashId, $data, function () use($deferred, $hashId) {
             $deferred->resolve($hashId);
         });
     });
     return $deferred->promise()->then(function ($hashId) use($redis) {
         $saddDeferred = new Deferred();
         $redis->sadd('garbages', $hashId, function () use($hashId, $saddDeferred) {
             $saddDeferred->resolve($hashId);
         });
         return $saddDeferred->promise();
     });
 }
예제 #3
0
 /**
  * @group connected
  */
 public function testCanConnectToRedis()
 {
     $test = $this;
     $trigger = false;
     $parameters = $this->getParameters();
     $options = $this->getOptions();
     $client = new Client($parameters, $options);
     $client->connect(function ($cbkClient, $cbkConnection) use($test, $client, &$trigger) {
         $trigger = true;
         $test->assertInstanceOf('Predis\\Async\\Client', $cbkClient);
         $test->assertInstanceOf('Predis\\Async\\Connection\\ConnectionInterface', $cbkConnection);
         $test->assertSame($client, $cbkClient);
         $client->disconnect();
     });
     $loop = $client->getEventLoop();
     $loop->addTimer(0.01, function () use($test, &$trigger) {
         $test->assertTrue($trigger, 'The client was unable to connect to Redis');
     });
     $loop->run();
 }
예제 #4
0
<?php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use BulkMock\BulkMockApp;
use Predis\Async\Client as PredisClient;
require dirname(__DIR__) . '/vendor/autoload.php';
$config = (require dirname(__DIR__) . '/config.php');
$mockApp = new BulkMockApp($config);
$server = IoServer::factory(new HttpServer(new WsServer($mockApp)), $config['bulk_server']['port']);
$client = new PredisClient($config['redis_conn_url'], $server->loop);
$client->connect(function ($client) use($mockApp) {
    echo "Connected to Redis, now listening for incoming messages...\n";
    $client->pubSubLoop('bulkmocksend', function ($event) use($mockApp) {
        echo "Received new Bulk Msg `{$event->payload}` from {$event->channel}.\n";
        $mockApp->processBulkMsg(json_decode($event->payload, true));
    });
});
$server->run();
예제 #5
0
<?php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use PremiumMock\PremiumMockApp;
use Predis\Async\Client as PredisClient;
require dirname(__DIR__) . '/vendor/autoload.php';
$config = (require dirname(__DIR__) . '/config.php');
$mockApp = new PremiumMockApp($config);
$server = IoServer::factory(new HttpServer(new WsServer($mockApp)), $config['ws_port']);
$client = new PredisClient($config['redis_conn_url'], $server->loop);
$client->connect(function ($client) use($mockApp) {
    echo "Connected to Redis, now listening for incoming messages...\n";
    $client->pubSubLoop('premiummockmt', function ($event) use($mockApp) {
        echo "Received MT `{$event->payload}` from {$event->channel}.\n";
        $mockApp->processMt(json_decode($event->payload, true));
    });
});
$server->run();
예제 #6
0
 public function testHandleLogWithGoodMessageNotImplementingJobInterface()
 {
     $worker = new WorkerPresence();
     $worker->setMemory(12345);
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) {
             $redis->disconnect();
             $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId));
             $phpunit->assertTrue($redisSync->sismember('garbages', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }