getConnectionInitializerByString($options, $value); } if (is_callable($value)) { return $this->getConnectionInitializer($options, $value); } else { throw new InvalidArgumentException(sprintf( '%s expects either a string or a callable value, %s given', static::class, is_object($value) ? get_class($value) : gettype($value) )); } } /** * Returns a connection initializer from a descriptive name. * * @param OptionsInterface $options Client options * @param string $description Identifier of a replication backend (`predis`, `sentinel`) * * @return callable */ protected function getConnectionInitializerByString(OptionsInterface $options, string $description) { switch ($description) { case 'redis': case 'redis-cluster': return function ($parameters, $options, $option) { return new RedisCluster($options->connections, new RedisStrategy($options->crc16)); }; case 'predis': return $this->getDefaultConnectionInitializer(); default: throw new InvalidArgumentException(sprintf( '%s expects either `predis`, `redis` or `redis-cluster` as valid string values, `%s` given', static::class, $description )); } } /** * Returns the default connection initializer. * * @return callable */ protected function getDefaultConnectionInitializer() { return function ($parameters, $options, $option) { return new PredisCluster(); }; } /** * {@inheritdoc} */ public function getDefault(OptionsInterface $options) { return $this->getConnectionInitializer( $options, $this->getDefaultConnectionInitializer() ); } }