Added Redis options name to support string type (#6188)

This commit is contained in:
Deeka Wong 2023-10-07 14:16:14 +08:00 committed by GitHub
parent f1c40efcf1
commit a5cd1fd8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# v3.0.39 - TBD
## Added
- [#6188](https://github.com/hyperf/hyperf/pull/6188) Added Redis options name to support string type.
# v3.0.38 - 2023-10-05
## Fixed

View File

@ -120,7 +120,20 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
$options = $this->config['options'] ?? [];
foreach ($options as $name => $value) {
// The name is int, value is string.
if (is_string($name)) {
$name = match (strtolower($name)) {
'serializer' => Redis::OPT_SERIALIZER, // 1
'prefix' => Redis::OPT_PREFIX, // 2
'read_timeout' => Redis::OPT_READ_TIMEOUT, // 3
'scan' => Redis::OPT_SCAN, // 4
'failover' => defined(Redis::class . '::OPT_SLAVE_FAILOVER') ? Redis::OPT_SLAVE_FAILOVER : 5, // 5
'keepalive' => Redis::OPT_TCP_KEEPALIVE, // 6
'compression' => Redis::OPT_COMPRESSION, // 7
'reply_literal' => Redis::OPT_REPLY_LITERAL, // 8
'compression_level' => Redis::OPT_COMPRESSION_LEVEL, // 9
default => $name,
};
}
$redis->setOption($name, $value);
}