Skip to content

Commit

Permalink
update CHANGELOG and comments
Browse files Browse the repository at this point in the history
cosmetic updates for #166
  • Loading branch information
deminy committed Dec 28, 2023
1 parent 7a973b8 commit 2ff30e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fixed:
Changed:

* MR swoole/library#160 : Allow to pass array key/index to the callback function of function _\Swoole\Coroutine::map()_. (by @maxiaozhi )
* MR swoole/library#166 : Support configurable options for _Redis_. (by @sy-records )
* Improved type declarations and return types.

## 5.1.1 (2023-11-26)
Expand Down
16 changes: 16 additions & 0 deletions src/core/Database/RedisConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class RedisConfig

protected int $dbIndex = 0;

/**
* @var array<int, mixed>
*/
protected array $options = [];

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

/**
* Add a configurable option.
*/
public function withOption(int $option, mixed $value): self
{
$this->options[$option] = $value;
return $this;
}

/**
* Add/override configurable options.
*
* @param array<int, mixed> $options
*/
public function setOptions(array $options): self
{
$this->options = $options;
return $this;
}

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

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

return $redis;
Expand Down

0 comments on commit 2ff30e0

Please sign in to comment.