diff --git a/pkg/redis/PRedis.php b/pkg/redis/PRedis.php index f76ad3efd..f8a1cf96e 100644 --- a/pkg/redis/PRedis.php +++ b/pkg/redis/PRedis.php @@ -34,6 +34,18 @@ public function __construct(array $config) throw new \LogicException('The package "predis/predis" must be installed. Please run "composer req predis/predis:^1.1" to install it'); } + if (array_key_exists('client', $config) && null !== $config['client']) { + if (!$config['client'] instanceof Client) { + 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']))); + } + $this->redis = $config['client']; + + $this->options = []; + $this->parameters = []; + + return; + } + $this->options = $config['predis_options']; $this->parameters = [ @@ -54,6 +66,11 @@ public function __construct(array $config) } } + public static function createWithClient(Client $client): self + { + return new self(['client' => $client]); + } + public function eval(string $script, array $keys = [], array $args = []) { try {