Skip to content
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ use Utopia\Queue;
use Utopia\Queue\Message;

$connection = new Queue\Connection\Redis('redis');

if ($connection->ping()) {
var_dump('Connection is ready.');
} else {
var_dump('Connection is not ready.');
}

$adapter = new Queue\Adapter\Swoole($connection, 12, 'my-queue');
$server = new Queue\Server($adapter);

Expand Down
1 change: 1 addition & 0 deletions src/Queue/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public function get(string $key): array|string|null;
public function setArray(string $key, array $value): bool;
public function increment(string $key): int;
public function decrement(string $key): int;
public function ping(): bool;
}
11 changes: 11 additions & 0 deletions src/Queue/Connection/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ public function listRange(string $key, int $total, int $offset): array
return array_map(fn (array $job) => new Message($job), $results);
}

public function ping(): bool
{
try {
$this->getRedis()->ping();

return true;
} catch (\Exception $e) {
return false;
}
}

protected function getRedis(): \Redis
{
if ($this->redis) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Queue/e2e/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public function testEvents(): void
{
$connection = new Redis('redis', 6379);

$this->assertTrue($connection->ping());

$client = new Client('workerman', $connection);
$client->resetStats();


foreach ($this->payloads as $payload) {
$this->assertTrue($client->enqueue($payload));
}
Expand Down