改名
This commit is contained in:
+8
-35
@@ -20,47 +20,20 @@ class Emit extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param int[] $users
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function emit(string $name, string $message)
|
public function emit(array $users, string $message)
|
||||||
{
|
{
|
||||||
$redis = Snowflake::app()->getRedis();
|
$table = Snowflake::app()->getTable('SYSTEM:ONLINE:PEOPLES');
|
||||||
if (!$redis->exists($name) || $redis->sCard($name) < 1) {
|
|
||||||
return;
|
foreach ($users as $user) {
|
||||||
|
$fd = $table->get((string)$user, ['clientId']);
|
||||||
|
|
||||||
|
Snowflake::push($fd, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$socket = Snowflake::app()->getSwoole();
|
|
||||||
foreach ($redis->sMembers($name) as $value) {
|
|
||||||
$socket->push($value, $message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param int $value
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function register(string $name, int $value)
|
|
||||||
{
|
|
||||||
redis()->sAdd($name, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param int|null $value
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function clear(string $name, ?int $value = null)
|
|
||||||
{
|
|
||||||
if (!empty($value)) {
|
|
||||||
redis()->sRem($name, $value);
|
|
||||||
} else {
|
|
||||||
redis()->del($name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ class Snowflake
|
|||||||
public static function push(int $fd, $data): mixed
|
public static function push(int $fd, $data): mixed
|
||||||
{
|
{
|
||||||
$server = static::getWebSocket();
|
$server = static::getWebSocket();
|
||||||
if (empty($server)) {
|
if (empty($server) || !$server->isEstablished($fd)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!is_string($data)) {
|
if (!is_string($data)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user