改进 集群

This commit is contained in:
iVampireSP.com 2023-02-08 14:00:04 +08:00
parent e0cdb3d45f
commit 9fb07ab438
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -23,7 +23,7 @@ public static function isSlave(): bool
return config('settings.node.type') === 'slave'; return config('settings.node.type') === 'slave';
} }
public static function publish($event, $data = []): void public static function publish($event, $data = [], $register = true): void
{ {
/** @noinspection PhpUndefinedMethodInspection */ /** @noinspection PhpUndefinedMethodInspection */
Redis::publish('cluster_ready', json_encode([ Redis::publish('cluster_ready', json_encode([
@ -37,7 +37,9 @@ public static function publish($event, $data = []): void
'data' => $data, 'data' => $data,
])); ]));
self::registerThisNode(false); if ($register) {
self::registerThisNode(false);
}
} }
public static function registerThisNode($report = true): void public static function registerThisNode($report = true): void
@ -75,6 +77,7 @@ public static function listen(string|array $events, callable $callback, bool $ig
ini_set('default_socket_timeout', -1); ini_set('default_socket_timeout', -1);
Redis::subscribe('cluster_ready', function ($message) use ($events, $callback, $ignore_self) { Redis::subscribe('cluster_ready', function ($message) use ($events, $callback, $ignore_self) {
echo $message;
$message = json_decode($message, true); $message = json_decode($message, true);
if ($ignore_self && $message['node']['id'] === config('settings.node.id')) { if ($ignore_self && $message['node']['id'] === config('settings.node.id')) {