Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add new RedisRepository #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Repositories/MemoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MemoryRepository implements Repository
* but it is currently not being used (i.e. in a resend queue).
*
* @return int
* @throws RepositoryException
*/
public function newMessageId(): int
{
Expand Down Expand Up @@ -194,11 +195,11 @@ public function getMatchingSubscriptions(string $topicName = null, int $subscrip
$result = [];

foreach ($this->subscriptions as $subscription) {
if (($topicName !== null) && !$subscription->matchTopicFilter($topicName)) {
if ($topicName !== null && !$subscription->matchTopicFilter($topicName)) {
continue;
}

if (($subscriptionId !== null) && ($subscription->getSubscriptionId() !== $subscriptionId)) {
if ($subscriptionId !== null && $subscription->getSubscriptionId() !== $subscriptionId) {
continue;
}

Expand Down
109 changes: 109 additions & 0 deletions src/Repositories/RedisConnectionSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

namespace PhpMqtt\Client\Repositories;

/**
* Connection settings DTO for Redis used by {@see RedisRepository}.
*
* @package PhpMqtt\Client\Repositories
*/
class RedisConnectionSettings
{
/** @var string|null */
private $host = null;

/** @var int */
private $port = 6379;

/** @var float */
private $connectTimeout = 5.0;

/** @var int */
private $database = 0;

/**
* @return string|null
*/
public function getHost(): ?string
{
return $this->host;
}

/**
* @param string $host
* @return RedisConnectionSettings
*/
public function setHost(string $host): RedisConnectionSettings
{
$clone = clone $this;

$clone->host = $host;

return $clone;
}

/**
* @return int
*/
public function getPort(): int
{
return $this->port;
}

/**
* @param int $port
* @return RedisConnectionSettings
*/
public function setPort(int $port): RedisConnectionSettings
{
$clone = clone $this;

$clone->port = $port;

return $clone;
}

/**
* @return float
*/
public function getConnectTimeout(): float
{
return $this->connectTimeout;
}

/**
* @param float $connectTimeout
* @return RedisConnectionSettings
*/
public function setConnectTimeout(float $connectTimeout): RedisConnectionSettings
{
$clone = clone $this;

$clone->connectTimeout = $connectTimeout;

return $clone;
}

/**
* @return int
*/
public function getDatabase(): int
{
return $this->database;
}

/**
* @param int $database
* @return RedisConnectionSettings
*/
public function setDatabase(int $database): RedisConnectionSettings
{
$clone = clone $this;

$clone->database = $database;

return $clone;
}
}
Loading