PredisConnection.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Illuminate\Redis\Connections;
  3. use Closure;
  4. use Illuminate\Contracts\Redis\Connection as ConnectionContract;
  5. /**
  6. * @mixin \Predis\Client
  7. */
  8. class PredisConnection extends Connection implements ConnectionContract
  9. {
  10. /**
  11. * Create a new Predis connection.
  12. *
  13. * @param \Predis\Client $client
  14. * @return void
  15. */
  16. public function __construct($client)
  17. {
  18. $this->client = $client;
  19. }
  20. /**
  21. * Subscribe to a set of given channels for messages.
  22. *
  23. * @param array|string $channels
  24. * @param \Closure $callback
  25. * @param string $method
  26. * @return void
  27. */
  28. public function createSubscription($channels, Closure $callback, $method = 'subscribe')
  29. {
  30. $loop = $this->pubSubLoop();
  31. call_user_func_array([$loop, $method], (array) $channels);
  32. foreach ($loop as $message) {
  33. if ($message->kind === 'message' || $message->kind === 'pmessage') {
  34. call_user_func($callback, $message->payload, $message->channel);
  35. }
  36. }
  37. unset($loop);
  38. }
  39. }