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