29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Redis 331<br />

.<br />

18 * The console command description.<br />

19 *<br />

20 * @var string<br />

21 */<br />

22 protected $description = 'Subscribe to a Redis channel';<br />

23<br />

24 /**<br />

25 * Execute the console command.<br />

26 *<br />

27 * @return mixed<br />

28 */<br />

29 public function handle()<br />

30 {<br />

31 Redis::subscribe(['test-channel'], function($message) {<br />

32 echo $message;<br />

33 });<br />

34 }<br />

35 }<br />

Now, we may publish messages to the channel using the publish method:<br />

.<br />

1 Route::get('publish', function () {<br />

2 // Route logic...<br />

3<br />

4 Redis::publish('test-channel', json_encode(['foo' => 'bar']));<br />

5 });<br />

Wildcard Subscriptions<br />

Using the psubscribe method, you may subscribe to a wildcard channel, which is useful for catching<br />

all messages on all channels. The $channel name will be passed as the second argument to the<br />

provided callback Closure:<br />

.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!