1 | <?php |
||
13 | class RedisClient implements ReplicationInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var LoopInterface |
||
17 | */ |
||
18 | protected $loop; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $serverId; |
||
24 | |||
25 | /** |
||
26 | * @var Client |
||
27 | */ |
||
28 | protected $publishClient; |
||
29 | |||
30 | /** |
||
31 | * @var Client |
||
32 | */ |
||
33 | protected $subscribeClient; |
||
34 | |||
35 | /** |
||
36 | * Mapping of subscribed channels, where the key is the channel name, |
||
37 | * and the value is the amount of connections which are subscribed to |
||
38 | * that channel. Used to keep track of whether we still need to stay |
||
39 | * subscribed to those channels with Redis. |
||
40 | * |
||
41 | * @var int[] |
||
42 | */ |
||
43 | protected $subscribedChannels = []; |
||
44 | |||
45 | /** |
||
46 | * RedisClient constructor. |
||
47 | */ |
||
48 | public function __construct() |
||
52 | |||
53 | /** |
||
54 | * Boot the RedisClient, initializing the connections |
||
55 | * |
||
56 | * @param LoopInterface $loop |
||
57 | * @return ReplicationInterface |
||
58 | */ |
||
59 | public function boot(LoopInterface $loop): ReplicationInterface |
||
75 | |||
76 | /** |
||
77 | * Handle a message received from Redis on a specific channel |
||
78 | * |
||
79 | * @param string $redisChannel |
||
80 | * @param string $payload |
||
81 | * @return bool |
||
82 | */ |
||
83 | protected function onMessage(string $redisChannel, string $payload) |
||
116 | |||
117 | /** |
||
118 | * Subscribe to a channel on behalf of websocket user |
||
119 | * |
||
120 | * @param string $appId |
||
121 | * @param string $channel |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function subscribe(string $appId, string $channel): bool |
||
137 | |||
138 | /** |
||
139 | * Unsubscribe from a channel on behalf of a websocket user |
||
140 | * |
||
141 | * @param string $appId |
||
142 | * @param string $channel |
||
143 | * @return bool |
||
144 | */ |
||
145 | public function unsubscribe(string $appId, string $channel): bool |
||
162 | |||
163 | /** |
||
164 | * Publish a message to a channel on behalf of a websocket user |
||
165 | * |
||
166 | * @param string $appId |
||
167 | * @param string $channel |
||
168 | * @param stdClass $payload |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function publish(string $appId, string $channel, stdClass $payload): bool |
||
180 | |||
181 | /** |
||
182 | * Build the Redis connection URL from Laravel database config |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | protected function getConnectionUri() |
||
204 | } |
||
205 |