Skip to content

Commit

Permalink
Add an example.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jul 3, 2017
1 parent 35349ab commit 5367b3e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,44 @@ And then run `composer install` from the terminal.
Above installation can also be simplify by using the following command:

composer require "laravie/streaming=~1.0"


### Example

```php

use Laravie\Streaming\Client;
use Laravie\Streaming\Listener;

$chat = new class('127.0.0.1', 6379) implements Listener {
public function __construct($host, $port) {
$client = new Client(compact('host', 'port'));
$client->connect($this);
}

public function subscribedChannels() {
return ['topic:*'];
}

public function onConnected($client) {
echo "Connected to redis!";
}

public function onSubscribed($client) {
echo "Subscribed to channel `topic:*`!";
}

public function onEmitted($event, $pubsub) {
// PUBLISH topic:laravel "Hello world"

# DESCRIBE $event
#
# {
# "kind": "pmessage",
# "pattern": "topic:*",
# "channel": "topic:laravel",
# "payload": "Hello world"
# }
}
}
```

0 comments on commit 5367b3e

Please sign in to comment.