Skip to content

Commit

Permalink
added key to getHostname to get hostname from ShardedClient
Browse files Browse the repository at this point in the history
  • Loading branch information
matthi4s committed Mar 26, 2020
1 parent dd93a8c commit ee1cf7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/ShardedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit ee1cf7b

Please sign in to comment.