PredisConnector.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Illuminate\Redis\Connectors;
  3. use Predis\Client;
  4. use Illuminate\Support\Arr;
  5. use Illuminate\Redis\Connections\PredisConnection;
  6. use Illuminate\Redis\Connections\PredisClusterConnection;
  7. class PredisConnector
  8. {
  9. /**
  10. * Create a new clustered Predis connection.
  11. *
  12. * @param array $config
  13. * @param array $options
  14. * @return \Illuminate\Redis\Connections\PredisConnection
  15. */
  16. public function connect(array $config, array $options)
  17. {
  18. $formattedOptions = array_merge(
  19. ['timeout' => 10.0], $options, Arr::pull($config, 'options', [])
  20. );
  21. return new PredisConnection(new Client($config, $formattedOptions));
  22. }
  23. /**
  24. * Create a new clustered Predis connection.
  25. *
  26. * @param array $config
  27. * @param array $clusterOptions
  28. * @param array $options
  29. * @return \Illuminate\Redis\Connections\PredisClusterConnection
  30. */
  31. public function connectToCluster(array $config, array $clusterOptions, array $options)
  32. {
  33. $clusterSpecificOptions = Arr::pull($config, 'options', []);
  34. return new PredisClusterConnection(new Client(array_values($config), array_merge(
  35. $options, $clusterOptions, $clusterSpecificOptions
  36. )));
  37. }
  38. }