Skip to content

Commit

Permalink
Support set options for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored and deminy committed Dec 28, 2023
1 parent a817ec3 commit 7a973b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/core/Database/RedisConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RedisConfig

protected int $dbIndex = 0;

protected string $prefix = '';
protected array $options = [];

public function getHost(): string
{
Expand Down Expand Up @@ -119,14 +119,20 @@ public function withDbIndex(int $dbIndex): self
return $this;
}

public function getPrefix(): string
public function withOption(int $option, mixed $value): self
{
return $this->prefix;
$this->options[$option] = $value;
return $this;
}

public function withPrefix(string $prefix): self
public function setOptions(array $options): self
{
$this->prefix = $prefix;
$this->options = $options;
return $this;
}

public function getOptions(): array
{
return $this->options;
}
}
6 changes: 4 additions & 2 deletions src/core/Database/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public function __construct(protected RedisConfig $config, int $size = self::DEF
}

/* Set Redis options. */
if ($this->config->getPrefix() !== '') {
$redis->setOption(\Redis::OPT_PREFIX, $this->config->getPrefix());
if ($this->config->getOptions() !== []) {
foreach ($this->config->getOptions() as $key => $value) {
$redis->setOption($key, $value);
}
}

return $redis;
Expand Down

0 comments on commit 7a973b8

Please sign in to comment.