From ee1cf7b4285afd706c74c0aad15ebe1862b8f9c5 Mon Sep 17 00:00:00 2001 From: Matthias Neid Date: Thu, 26 Mar 2020 13:59:03 +0100 Subject: [PATCH] added key to getHostname to get hostname from ShardedClient --- src/Client.php | 6 +++++- src/ClientInterface.php | 6 +++++- src/ShardedClient.php | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 43ca553..148be9a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -72,7 +72,11 @@ public function __construct($hostname = "localhost:2379", $username = false, $pa $this->password = $password; } - public function getHostname(): string + /** + * @param string|null $key + * @return string + */ + public function getHostname(?string $key = null): string { return $this->hostname; } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index db74f85..4ab5340 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -11,7 +11,11 @@ */ interface ClientInterface { - public function getHostname(): string; + /** + * @param string|null $key + * @return string + */ + public function getHostname(?string $key = null): string; /** * Put a value into the key store diff --git a/src/ShardedClient.php b/src/ShardedClient.php index 3374d45..6f6096c 100644 --- a/src/ShardedClient.php +++ b/src/ShardedClient.php @@ -69,9 +69,15 @@ protected function getClientFromKey(string $key): ClientInterface return $this->keyCache[$key]; } - - public function getHostname(): string + /** + * @inheritDoc + * @throws \Flexihash\Exception + */ + public function getHostname(?string $key = null): string { + if ($key) { + return $this->getClientFromKey($key)->getHostname($key); + } return implode("-", array_keys($this->clients)); }