-
Notifications
You must be signed in to change notification settings - Fork 1
/
Monitor.php
78 lines (69 loc) · 1.65 KB
/
Monitor.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the Tusk RedisMq package.
*
* (c) 2012 Tusk PHP Components <frizzy@paperjaw.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tusk\RedisMq;
/**
* Monitor
*
* @author Bernard van Niekerk <frizzy@paperjaw.com>
*/
class Monitor
{
private $connection;
/**
* Construct
*
* @param Connection $connection Connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
/**
* Get channels
*
* @param boolean $includeRpc Include RPC channels
*
* @return array Channels
*/
public function getChannels($includeRpc = false)
{
$channels = $this->connection->getRedis()->keys(
sprintf(
'%s*',
$this->connection->formatKey('')
)
);
$list = array();
foreach ($channels as $channel) {
$channel = substr(
$channel,
strlen($this->connection->formatKey(''))
);
if (substr($channel, 0, 4) == 'rpc:' && false == $includeRpc) {
continue;
}
if (substr($channel, 0, 4) == 'rpc_') {
continue;
}
$list[] = $channel;
}
return $list;
}
/**
* Get channel queue length
*/
public function getChannelQueueLength($channel)
{
$length = $this->connection->getRedis()->llen(
$this->connection->formatKey($channel)
);
return $length;
}
}