Skip to content

Commit 9f502fc

Browse files
committed
feat: allow creating PRedis with a client
1 parent f5759ec commit 9f502fc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/redis/PRedis.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public function __construct(array $config)
3434
throw new \LogicException('The package "predis/predis" must be installed. Please run "composer req predis/predis:^1.1" to install it');
3535
}
3636

37+
if (array_key_exists('client', $config) && null !== $config['client']) {
38+
if (!$config['client'] instanceof Client) {
39+
throw new \InvalidArgumentException(sprintf('%s configuration property is expected to be an instance of %s class. %s was passed instead.', 'client', Client::class, gettype($config['client'])));
40+
}
41+
$this->redis = $config['client'];
42+
43+
$this->options = [];
44+
$this->parameters = [];
45+
46+
return;
47+
}
48+
3749
$this->options = $config['predis_options'];
3850

3951
$this->parameters = [
@@ -54,6 +66,11 @@ public function __construct(array $config)
5466
}
5567
}
5668

69+
public static function createWithClient(Client $client): self
70+
{
71+
return new self(['client' => $client]);
72+
}
73+
5774
public function eval(string $script, array $keys = [], array $args = [])
5875
{
5976
try {

0 commit comments

Comments
 (0)