[Cache] Make Redis initializers static
This commit is contained in:
parent
674382b7ea
commit
ad8de57b91
@ -174,7 +174,7 @@ trait RedisTrait
|
|||||||
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
|
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
|
||||||
$redis = new $class();
|
$redis = new $class();
|
||||||
|
|
||||||
$initializer = function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
|
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
|
||||||
try {
|
try {
|
||||||
@$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
|
@$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ trait RedisTrait
|
|||||||
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
|
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
|
||||||
}
|
}
|
||||||
} elseif (is_a($class, \RedisCluster::class, true)) {
|
} elseif (is_a($class, \RedisCluster::class, true)) {
|
||||||
$initializer = function () use ($class, $params, $dsn, $hosts) {
|
$initializer = static function () use ($class, $params, $dsn, $hosts) {
|
||||||
foreach ($hosts as $i => $host) {
|
foreach ($hosts as $i => $host) {
|
||||||
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
|
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user