Skip to content

Commit

Permalink
Support set prefix for redis database
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Dec 27, 2023
1 parent 4a621c9 commit 1dc4a86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/Database/RedisConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class RedisConfig

protected int $dbIndex = 0;

protected string $prefix = '';

public function getHost(): string
{
return $this->host;
Expand Down Expand Up @@ -116,4 +118,15 @@ public function withDbIndex(int $dbIndex): self
$this->dbIndex = $dbIndex;
return $this;
}

public function getPrefix(): string
{
return $this->prefix;
}

public function withPrefix(string $prefix): self
{
$this->prefix = $prefix;
return $this;
}
}
6 changes: 6 additions & 0 deletions src/core/Database/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function __construct(protected RedisConfig $config, int $size = self::DEF
if ($this->config->getDbIndex() !== 0) {
$redis->select($this->config->getDbIndex());
}

/* Set Redis options. */
if ($this->config->getPrefix() !== '') {
$redis->setOption(Redis::OPT_PREFIX, $this->config->getPrefix());
}

return $redis;
}, $size);
}
Expand Down

0 comments on commit 1dc4a86

Please sign in to comment.