Replaced __call with direct function call

This commit is contained in:
Alex Renoki 2020-09-06 13:13:03 +03:00
parent c078e5a2b7
commit bd3aa90b65
2 changed files with 31 additions and 31 deletions

View File

@ -104,7 +104,7 @@ class RedisClient extends LocalClient
$payload = json_encode($payload);
$this->publishClient->__call('publish', [$this->getTopicName($appId, $channel), $payload]);
$this->publishClient->publish($this->getTopicName($appId, $channel), $payload);
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_MESSAGE_PUBLISHED, [
'channel' => $channel,
@ -127,7 +127,7 @@ class RedisClient extends LocalClient
{
if (! isset($this->subscribedChannels["{$appId}:{$channel}"])) {
// We're not subscribed to the channel yet, subscribe and set the count to 1
$this->subscribeClient->__call('subscribe', [$this->getTopicName($appId, $channel)]);
$this->subscribeClient->subscribe($this->getTopicName($appId, $channel));
$this->subscribedChannels["{$appId}:{$channel}"] = 1;
} else {
// Increment the subscribe count if we've already subscribed
@ -161,7 +161,7 @@ class RedisClient extends LocalClient
// If we no longer have subscriptions to that channel, unsubscribe
if ($this->subscribedChannels["{$appId}:{$channel}"] < 1) {
$this->subscribeClient->__call('unsubscribe', [$this->getTopicName($appId, $channel)]);
$this->subscribeClient->unsubscribe($this->getTopicName($appId, $channel));
unset($this->subscribedChannels["{$appId}:{$channel}"]);
}
@ -183,9 +183,9 @@ class RedisClient extends LocalClient
*/
public function subscribeToApp($appId): bool
{
$this->subscribeClient->__call('subscribe', [$this->getTopicName($appId)]);
$this->subscribeClient->subscribe($this->getTopicName($appId));
$this->publishClient->__call('hincrby', [$this->getTopicName($appId), 'connections', 1]);
$this->publishClient->hincrby($this->getTopicName($appId), 'connections', 1);
return true;
}
@ -198,9 +198,9 @@ class RedisClient extends LocalClient
*/
public function unsubscribeFromApp($appId): bool
{
$this->subscribeClient->__call('unsubscribe', [$this->getTopicName($appId)]);
$this->subscribeClient->unsubscribe($this->getTopicName($appId));
$this->publishClient->__call('hincrby', [$this->getTopicName($appId), 'connections', -1]);
$this->publishClient->hincrby($this->getTopicName($appId), 'connections', -1);
return true;
}
@ -217,7 +217,7 @@ class RedisClient extends LocalClient
*/
public function joinChannel($appId, string $channel, string $socketId, string $data)
{
$this->publishClient->__call('hset', [$this->getTopicName($appId, $channel), $socketId, $data]);
$this->publishClient->hset($this->getTopicName($appId, $channel), $socketId, $data);
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_JOINED_CHANNEL, [
'channel' => $channel,
@ -239,7 +239,7 @@ class RedisClient extends LocalClient
*/
public function leaveChannel($appId, string $channel, string $socketId)
{
$this->publishClient->__call('hdel', [$this->getTopicName($appId, $channel), $socketId]);
$this->publishClient->hdel($this->getTopicName($appId, $channel), $socketId);
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_LEFT_CHANNEL, [
'channel' => $channel,
@ -258,7 +258,7 @@ class RedisClient extends LocalClient
*/
public function channelMembers($appId, string $channel): PromiseInterface
{
return $this->publishClient->__call('hgetall', [$this->getTopicName($appId, $channel)])
return $this->publishClient->hgetall($this->getTopicName($appId, $channel))
->then(function ($members) {
// The data is expected as objects, so we need to JSON decode
return array_map(function ($user) {
@ -279,7 +279,7 @@ class RedisClient extends LocalClient
$this->publishClient->__call('multi', []);
foreach ($channelNames as $channel) {
$this->publishClient->__call('hlen', [$this->getTopicName($appId, $channel)]);
$this->publishClient->hlen($this->getTopicName($appId, $channel));
}
return $this->publishClient->__call('exec', [])

View File

@ -59,7 +59,7 @@ class RedisStatisticsLogger implements StatisticsLogger
public function webSocketMessage($appId)
{
$this->ensureAppIsSet($appId)
->__call('hincrby', [$this->getHash($appId), 'websocket_message_count', 1]);
->hincrby($this->getHash($appId), 'websocket_message_count', 1);
}
/**
@ -71,7 +71,7 @@ class RedisStatisticsLogger implements StatisticsLogger
public function apiMessage($appId)
{
$this->ensureAppIsSet($appId)
->__call('hincrby', [$this->getHash($appId), 'api_message_count', 1]);
->hincrby($this->getHash($appId), 'api_message_count', 1);
}
/**
@ -84,13 +84,13 @@ class RedisStatisticsLogger implements StatisticsLogger
{
// Increment the current connections count by 1.
$incremented = $this->ensureAppIsSet($appId)
->__call('hincrby', [$this->getHash($appId), 'current_connection_count', 1]);
->hincrby($this->getHash($appId), 'current_connection_count', 1);
$incremented->then(function ($currentConnectionCount) use ($appId) {
// Get the peak connections count from Redis.
$peakConnectionCount = $this->replicator
->getPublishClient()
->__call('hget', [$this->getHash($appId), 'peak_connection_count']);
->hget($this->getHash($appId), 'peak_connection_count');
$peakConnectionCount->then(function ($currentPeakConnectionCount) use ($currentConnectionCount, $appId) {
// Extract the greatest number between the current peak connection count
@ -103,7 +103,7 @@ class RedisStatisticsLogger implements StatisticsLogger
// Then set it to the database.
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'peak_connection_count', $peakConnectionCount]);
->hset($this->getHash($appId), 'peak_connection_count', $peakConnectionCount);
});
});
}
@ -118,13 +118,13 @@ class RedisStatisticsLogger implements StatisticsLogger
{
// Decrement the current connections count by 1.
$decremented = $this->ensureAppIsSet($appId)
->__call('hincrby', [$this->getHash($appId), 'current_connection_count', -1]);
->hincrby($this->getHash($appId), 'current_connection_count', -1);
$decremented->then(function ($currentConnectionCount) use ($appId) {
// Get the peak connections count from Redis.
$peakConnectionCount = $this->replicator
->getPublishClient()
->__call('hget', [$this->getHash($appId), 'peak_connection_count']);
->hget($this->getHash($appId), 'peak_connection_count');
$peakConnectionCount->then(function ($currentPeakConnectionCount) use ($currentConnectionCount, $appId) {
// Extract the greatest number between the current peak connection count
@ -137,7 +137,7 @@ class RedisStatisticsLogger implements StatisticsLogger
// Then set it to the database.
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'peak_connection_count', $peakConnectionCount]);
->hset($this->getHash($appId), 'peak_connection_count', $peakConnectionCount);
});
});
}
@ -152,13 +152,13 @@ class RedisStatisticsLogger implements StatisticsLogger
$this->lock()->get(function () {
$setMembers = $this->replicator
->getPublishClient()
->__call('smembers', ['laravel-websockets:apps']);
->smembers('laravel-websockets:apps');
$setMembers->then(function ($members) {
foreach ($members as $appId) {
$member = $this->replicator
->getPublishClient()
->__call('hgetall', [$this->getHash($appId)]);
->hgetall($this->getHash($appId));
$member->then(function ($statistic) use ($appId) {
if (! $statistic) {
@ -201,7 +201,7 @@ class RedisStatisticsLogger implements StatisticsLogger
{
$this->replicator
->getPublishClient()
->__call('sadd', ['laravel-websockets:apps', $appId]);
->sadd('laravel-websockets:apps', $appId);
return $this->replicator->getPublishClient();
}
@ -217,19 +217,19 @@ class RedisStatisticsLogger implements StatisticsLogger
{
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'current_connection_count', $currentConnectionCount]);
->hset($this->getHash($appId), 'current_connection_count', $currentConnectionCount);
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'peak_connection_count', $currentConnectionCount]);
->hset($this->getHash($appId), 'peak_connection_count', $currentConnectionCount);
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'websocket_message_count', 0]);
->hset($this->getHash($appId), 'websocket_message_count', 0);
$this->replicator
->getPublishClient()
->__call('hset', [$this->getHash($appId), 'api_message_count', 0]);
->hset($this->getHash($appId), 'api_message_count', 0);
}
/**
@ -243,23 +243,23 @@ class RedisStatisticsLogger implements StatisticsLogger
{
$this->replicator
->getPublishClient()
->__call('hdel', [$this->getHash($appId), 'current_connection_count']);
->hdel($this->getHash($appId), 'current_connection_count');
$this->replicator
->getPublishClient()
->__call('hdel', [$this->getHash($appId), 'peak_connection_count']);
->hdel($this->getHash($appId), 'peak_connection_count');
$this->replicator
->getPublishClient()
->__call('hdel', [$this->getHash($appId), 'websocket_message_count']);
->hdel($this->getHash($appId), 'websocket_message_count');
$this->replicator
->getPublishClient()
->__call('hdel', [$this->getHash($appId), 'api_message_count']);
->hdel($this->getHash($appId), 'api_message_count');
$this->replicator
->getPublishClient()
->__call('srem', ['laravel-websockets:apps', $appId]);
->srem('laravel-websockets:apps', $appId);
}
/**