From aebc38ff8ef8ec17c4fbc02a7498bb599f8b5fa7 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Wed, 9 Dec 2020 11:37:03 +0200 Subject: [PATCH] Moved $serverId to local channel manager --- src/ChannelManagers/LocalChannelManager.php | 18 ++++++++++++++++++ src/ChannelManagers/RedisChannelManager.php | 21 ++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/ChannelManagers/LocalChannelManager.php b/src/ChannelManagers/LocalChannelManager.php index 919a239..864857b 100644 --- a/src/ChannelManagers/LocalChannelManager.php +++ b/src/ChannelManagers/LocalChannelManager.php @@ -53,6 +53,13 @@ class LocalChannelManager implements ChannelManager */ protected $store; + /** + * The unique server identifier. + * + * @var string + */ + protected $serverId; + /** * The lock name to use on Array to avoid multiple * actions that might lead to multiple processings. @@ -71,6 +78,7 @@ class LocalChannelManager implements ChannelManager public function __construct(LoopInterface $loop, $factoryClass = null) { $this->store = new ArrayStore; + $this->serverId = Str::uuid()->toString(); } /** @@ -509,6 +517,16 @@ class LocalChannelManager implements ChannelManager return Channel::class; } + /** + * Get the unique identifier for the server. + * + * @return string + */ + public function getServerId(): string + { + return $this->serverId; + } + /** * Get a new ArrayLock instance to avoid race conditions. * diff --git a/src/ChannelManagers/RedisChannelManager.php b/src/ChannelManagers/RedisChannelManager.php index 01e3419..b13ecf0 100644 --- a/src/ChannelManagers/RedisChannelManager.php +++ b/src/ChannelManagers/RedisChannelManager.php @@ -26,13 +26,6 @@ class RedisChannelManager extends LocalChannelManager */ protected $loop; - /** - * The unique server identifier. - * - * @var string - */ - protected $serverId; - /** * The pub client. * @@ -71,6 +64,8 @@ class RedisChannelManager extends LocalChannelManager */ public function __construct(LoopInterface $loop, $factoryClass = null) { + parent::construct($loop, $factoryClass); + $this->loop = $loop; $this->redis = Redis::connection( @@ -88,8 +83,6 @@ class RedisChannelManager extends LocalChannelManager $this->subscribeClient->on('message', function ($channel, $payload) { $this->onMessage($channel, $payload); }); - - $this->serverId = Str::uuid()->toString(); } /** @@ -538,16 +531,6 @@ class RedisChannelManager extends LocalChannelManager return $this->getPublishClient(); } - /** - * Get the unique identifier for the server. - * - * @return string - */ - public function getServerId(): string - { - return $this->serverId; - } - /** * Increment the subscribed count number. *