Skip to content

Instantly share code, notes, and snippets.

@insytes
Created June 6, 2018 14:28
Show Gist options
  • Save insytes/656b33c19a33a9e49254e4de081c3d72 to your computer and use it in GitHub Desktop.
Save insytes/656b33c19a33a9e49254e4de081c3d72 to your computer and use it in GitHub Desktop.
ReactPHP Redis Pub/Sub
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set("default_socket_timeout", 10);
require __DIR__ . "/../../vendor/autoload.php";
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$channel = isset($argv[1]) ? $argv[1] : "default";
$factory->createClient("redis://:[email protected]:6379")->then(function (Clue\React\Redis\Client $client) use ($channel) {
$client->subscribe($channel)->then(function () use (&$channel) {
echo "Now subscribed to $channel " . PHP_EOL;
});
$client->on("message", function ($channel, $message) {
echo 'Message on ' . $channel . ': ' . $message . PHP_EOL;
});
}, function (Exception $e) {
print $e->getMessage() . "\n";
});
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment