Refactored some functions
This commit is contained in:
parent
f04cce73d3
commit
86fbf76a0e
|
|
@ -130,9 +130,8 @@ class RedisChannelManager extends LocalChannelManager
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->getPublishClient()->sadd(
|
$this->addChannelToSet(
|
||||||
$this->getRedisKey($connection->app->id, null, ['channels']),
|
$connection->app->id, $channelName
|
||||||
$channelName
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->incrementSubscriptionsCount(
|
$this->incrementSubscriptionsCount(
|
||||||
|
|
@ -157,25 +156,19 @@ class RedisChannelManager extends LocalChannelManager
|
||||||
if ($count === 0) {
|
if ($count === 0) {
|
||||||
$this->unsubscribeFromTopic($connection->app->id, $channelName);
|
$this->unsubscribeFromTopic($connection->app->id, $channelName);
|
||||||
|
|
||||||
$this->getPublishClient()->srem(
|
$this->removeChannelFromSet($connection->app->id, $channelName);
|
||||||
$this->getRedisKey($connection->app->id, null, ['channels']),
|
|
||||||
$channelName
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$increment = $this->incrementSubscriptionsCount(
|
$this->decrementSubscriptionsCount(
|
||||||
$connection->app->id, $channelName, -1
|
$connection->app->id, $channelName,
|
||||||
)
|
)
|
||||||
->then(function ($count) use ($connection, $channelName) {
|
->then(function ($count) use ($connection, $channelName) {
|
||||||
if ($count < 1) {
|
if ($count < 1) {
|
||||||
$this->unsubscribeFromTopic($connection->app->id, $channelName);
|
$this->unsubscribeFromTopic($connection->app->id, $channelName);
|
||||||
|
|
||||||
$this->getPublishClient()->srem(
|
$this->removeChannelFromSet($connection->app->id, $channelName);
|
||||||
$this->getRedisKey($connection->app->id, null, ['channels']),
|
|
||||||
$channelName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -456,6 +449,49 @@ class RedisChannelManager extends LocalChannelManager
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrement the subscribed count number.
|
||||||
|
*
|
||||||
|
* @param string|int $appId
|
||||||
|
* @param string|null $channel
|
||||||
|
* @param int $decrement
|
||||||
|
* @return PromiseInterface
|
||||||
|
*/
|
||||||
|
public function decrementSubscriptionsCount($appId, string $channel = null, int $increment = 1)
|
||||||
|
{
|
||||||
|
return $this->incrementSubscriptionsCount($appId, $channel, $increment * -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a channel to the set list.
|
||||||
|
*
|
||||||
|
* @param string|int $appId
|
||||||
|
* @param string $channel
|
||||||
|
* @return PromiseInterface
|
||||||
|
*/
|
||||||
|
public function addChannelToSet($appId, string $channel)
|
||||||
|
{
|
||||||
|
return $this->getPublishClient()->sadd(
|
||||||
|
$this->getRedisKey($appId, null, ['channels']),
|
||||||
|
$channel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a channel from the set list.
|
||||||
|
*
|
||||||
|
* @param string|int $appId
|
||||||
|
* @param string $channel
|
||||||
|
* @return PromiseInterface
|
||||||
|
*/
|
||||||
|
public function removeChannelFromSet($appId, string $channel)
|
||||||
|
{
|
||||||
|
return $this->getPublishClient()->srem(
|
||||||
|
$this->getRedisKey($appId, null, ['channels']),
|
||||||
|
$channel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set data for a topic. Might be used for the presence channels.
|
* Set data for a topic. Might be used for the presence channels.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue