|
@@ 80-112 (lines=33) @@
|
| 77 |
|
* @param string|int $appId |
| 78 |
|
* @return void |
| 79 |
|
*/ |
| 80 |
|
public function connection($appId) |
| 81 |
|
{ |
| 82 |
|
// Increment the current connections count by 1. |
| 83 |
|
$this->ensureAppIsInSet($appId) |
| 84 |
|
->hincrby( |
| 85 |
|
$this->channelManager->getRedisKey($appId, null, ['stats']), |
| 86 |
|
'current_connections_count', 1 |
| 87 |
|
) |
| 88 |
|
->then(function ($currentConnectionsCount) use ($appId) { |
| 89 |
|
// Get the peak connections count from Redis. |
| 90 |
|
$this->channelManager |
| 91 |
|
->getPublishClient() |
| 92 |
|
->hget( |
| 93 |
|
$this->channelManager->getRedisKey($appId, null, ['stats']), |
| 94 |
|
'peak_connections_count' |
| 95 |
|
) |
| 96 |
|
->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
| 97 |
|
// Extract the greatest number between the current peak connection count |
| 98 |
|
// and the current connection number. |
| 99 |
|
$peakConnectionsCount = is_null($currentPeakConnectionCount) |
| 100 |
|
? $currentConnectionsCount |
| 101 |
|
: max($currentPeakConnectionCount, $currentConnectionsCount); |
| 102 |
|
|
| 103 |
|
// Then set it to the database. |
| 104 |
|
$this->channelManager |
| 105 |
|
->getPublishClient() |
| 106 |
|
->hset( |
| 107 |
|
$this->channelManager->getRedisKey($appId, null, ['stats']), |
| 108 |
|
'peak_connections_count', $peakConnectionsCount |
| 109 |
|
); |
| 110 |
|
}); |
| 111 |
|
}); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
/** |
| 115 |
|
* Handle disconnections. |
|
@@ 120-152 (lines=33) @@
|
| 117 |
|
* @param string|int $appId |
| 118 |
|
* @return void |
| 119 |
|
*/ |
| 120 |
|
public function disconnection($appId) |
| 121 |
|
{ |
| 122 |
|
// Decrement the current connections count by 1. |
| 123 |
|
$this->ensureAppIsInSet($appId) |
| 124 |
|
->hincrby($this->channelManager->getRedisKey($appId, null, ['stats']), 'current_connections_count', -1) |
| 125 |
|
->then(function ($currentConnectionsCount) use ($appId) { |
| 126 |
|
// Get the peak connections count from Redis. |
| 127 |
|
$this->channelManager |
| 128 |
|
->getPublishClient() |
| 129 |
|
->hget($this->channelManager->getRedisKey($appId, null, ['stats']), 'peak_connections_count') |
| 130 |
|
->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
| 131 |
|
// Extract the greatest number between the current peak connection count |
| 132 |
|
// and the current connection number. |
| 133 |
|
$peakConnectionsCount = is_null($currentPeakConnectionCount) |
| 134 |
|
? $currentConnectionsCount |
| 135 |
|
: max($currentPeakConnectionCount, $currentConnectionsCount); |
| 136 |
|
|
| 137 |
|
// Then set it to the database. |
| 138 |
|
$this->channelManager |
| 139 |
|
->getPublishClient() |
| 140 |
|
->hset( |
| 141 |
|
$this->channelManager->getRedisKey($appId, null, ['stats']), |
| 142 |
|
'peak_connections_count', $peakConnectionsCount |
| 143 |
|
); |
| 144 |
|
}); |
| 145 |
|
}); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
/** |
| 149 |
|
* Save all the stored statistics. |
| 150 |
|
* |
| 151 |
|
* @return void |
| 152 |
|
*/ |
| 153 |
|
public function save() |
| 154 |
|
{ |
| 155 |
|
$this->lock()->get(function () { |