1 | <?php |
||
10 | class RedisCollector extends MemoryCollector |
||
11 | { |
||
12 | /** |
||
13 | * The Redis manager instance. |
||
14 | * |
||
15 | * @var \Illuminate\Redis\RedisManager |
||
16 | */ |
||
17 | protected $redis; |
||
18 | |||
19 | /** |
||
20 | * The set name for the Redis storage. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected static $redisSetName = 'laravel-websockets:apps'; |
||
25 | |||
26 | /** |
||
27 | * The lock name to use on Redis to avoid multiple |
||
28 | * collector-to-store actions that may result |
||
29 | * in multiple data points set to the store. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected static $redisLockName = 'laravel-websockets:lock'; |
||
34 | |||
35 | /** |
||
36 | * Initialize the logger. |
||
37 | * |
||
38 | * @return void |
||
|
|||
39 | */ |
||
40 | public function __construct() |
||
48 | |||
49 | /** |
||
50 | * Handle the incoming websocket message. |
||
51 | * |
||
52 | * @param string|int $appId |
||
53 | * @return void |
||
54 | */ |
||
55 | public function webSocketMessage($appId) |
||
63 | |||
64 | /** |
||
65 | * Handle the incoming API message. |
||
66 | * |
||
67 | * @param string|int $appId |
||
68 | * @return void |
||
69 | */ |
||
70 | public function apiMessage($appId) |
||
78 | |||
79 | /** |
||
80 | * Handle the new conection. |
||
81 | * |
||
82 | * @param string|int $appId |
||
83 | * @return void |
||
84 | */ |
||
85 | public function connection($appId) |
||
118 | |||
119 | /** |
||
120 | * Handle disconnections. |
||
121 | * |
||
122 | * @param string|int $appId |
||
123 | * @return void |
||
124 | */ |
||
125 | public function disconnection($appId) |
||
158 | |||
159 | /** |
||
160 | * Save all the stored statistics. |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | public function save() |
||
198 | |||
199 | /** |
||
200 | * Flush the stored statistics. |
||
201 | * |
||
202 | * @return void |
||
203 | */ |
||
204 | public function flush() |
||
212 | |||
213 | /** |
||
214 | * Get the saved statistics. |
||
215 | * |
||
216 | * @return PromiseInterface[array] |
||
217 | */ |
||
218 | public function getStatistics(): PromiseInterface |
||
240 | |||
241 | /** |
||
242 | * Get the saved statistics for an app. |
||
243 | * |
||
244 | * @param string|int $appId |
||
245 | * @return PromiseInterface[\BeyondCode\LaravelWebSockets\Statistics\Statistic|null] |
||
246 | */ |
||
247 | public function getAppStatistics($appId): PromiseInterface |
||
258 | |||
259 | /** |
||
260 | * Reset the statistics to a specific connection count. |
||
261 | * |
||
262 | * @param string|int $appId |
||
263 | * @param int $currentConnectionCount |
||
264 | * @return void |
||
265 | */ |
||
266 | public function resetStatistics($appId, int $currentConnectionCount) |
||
296 | |||
297 | /** |
||
298 | * Remove all app traces from the database if no connections have been set |
||
299 | * in the meanwhile since last save. |
||
300 | * |
||
301 | * @param string|int $appId |
||
302 | * @return void |
||
303 | */ |
||
304 | public function resetAppTraces($appId) |
||
338 | |||
339 | /** |
||
340 | * Ensure the app id is stored in the Redis database. |
||
341 | * |
||
342 | * @param string|int $appId |
||
343 | * @return \Clue\React\Redis\Client |
||
344 | */ |
||
345 | protected function ensureAppIsInSet($appId) |
||
353 | |||
354 | /** |
||
355 | * Get a new RedisLock instance to avoid race conditions. |
||
356 | * |
||
357 | * @return \Illuminate\Cache\CacheLock |
||
358 | */ |
||
359 | protected function lock() |
||
363 | |||
364 | /** |
||
365 | * Transform the Redis' list of key after value |
||
366 | * to key-value pairs. |
||
367 | * |
||
368 | * @param array $list |
||
369 | * @return array |
||
370 | */ |
||
371 | protected function listToKeyValue(array $list) |
||
384 | |||
385 | /** |
||
386 | * Transform a list coming from a Redis list |
||
387 | * to a Statistic instance. |
||
388 | * |
||
389 | * @param string|int $appId |
||
390 | * @param array $list |
||
391 | * @return \BeyondCode\LaravelWebSockets\Statistics\Statistic |
||
392 | */ |
||
393 | protected function listToStatisticInstance($appId, array $list) |
||
403 | } |
||
404 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.