Skip to content

Commit

Permalink
Add pubsub example
Browse files Browse the repository at this point in the history
Fixes #85.
  • Loading branch information
kelunik committed Nov 19, 2023
1 parent 5c14a57 commit 32350df
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/pubsub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use Amp\Redis\RedisSubscriber;
use function Amp\async;
use function Amp\delay;
use function Amp\Redis\createRedisClient;
use function Amp\Redis\createRedisConnector;

$client = createRedisClient('redis://');
$subscriber = new RedisSubscriber(createRedisConnector('redis://'));

$subscription = $subscriber->subscribe('amphp');

async(function () use ($client) {
delay(3); // wait for subscription to be active

$client->publish('amphp', 'New release is out!');
});

foreach ($subscription as $message) {
var_dump($message);

break;
}

0 comments on commit 32350df

Please sign in to comment.