[Cache] fix setting "read_timeout" when using Redis

This commit is contained in:
Nicolas Grekas 2020-12-10 17:45:19 +01:00
parent f4a02b4603
commit 7acca31e66
1 changed files with 2 additions and 2 deletions

View File

@ -176,7 +176,7 @@ trait RedisTrait
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
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'], $params['read_timeout']);
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
$isConnected = $redis->isConnected();
@ -188,7 +188,6 @@ trait RedisTrait
if ((null !== $auth && !$redis->auth($auth))
|| ($params['dbindex'] && !$redis->select($params['dbindex']))
|| ($params['read_timeout'] && !$redis->setOption(\Redis::OPT_READ_TIMEOUT, $params['read_timeout']))
) {
$e = preg_replace('/^ERR /', '', $redis->getLastError());
throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e.'.');
@ -215,6 +214,7 @@ trait RedisTrait
}
$params['lazy_connect'] = $params['lazy'] ?? true;
$params['connect_timeout'] = $params['timeout'];
$params['read_timeout'] = $params['read_timeout'];
try {
$redis = new $class($hosts, $params);