Skip to content

Commit

Permalink
Redis adapter for Swoole
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Apr 21, 2024
1 parent aa95c26 commit ef86861
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Queue/Adapter/Swoole/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ class Redis extends ConnectionRedis
{
protected RedisPool $pool;

protected int $poolSize = 50;
protected int $poolSize = 5;

public function __construct(string $host, int $port = 6379, ?string $user = null, ?string $password = null)
{
parent::__construct($host, $port, $user, $password);
$this->host = $host;
$this->port = $port;
$this->user = $user;
$this->password = $password;

$auth = (empty($this->user) || empty($this->password)) ? $this->user.$this->password : implode(':', array_filter([$this->user, $this->password]));

$this->pool = new RedisPool((new RedisConfig())
->withHost($this->host)
->withPort((int)$this->port)
->withAuth((string)$this->password)
, $this->poolSize);
->withPort($this->port)
->withAuth($auth), $this->poolSize);
}

public function getConnection(): void
Expand All @@ -30,10 +34,19 @@ public function getConnection(): void

public function putConnection(): void
{
if(is_null($this->redis)) {
if (is_null($this->redis)) {
return;
}

$this->pool->put($this->redis);
}
}

protected function getRedis(): \Redis
{
if (empty($this->redis)) {
$this->redis = $this->pool->get();
}

return $this->redis;
}
}

0 comments on commit ef86861

Please sign in to comment.