| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Redis\Connectors;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Contracts\Redis\Connector;
|
|
|
6 |
use Illuminate\Redis\Connections\PredisClusterConnection;
|
|
|
7 |
use Illuminate\Redis\Connections\PredisConnection;
|
|
|
8 |
use Illuminate\Support\Arr;
|
|
|
9 |
use Predis\Client;
|
|
|
10 |
|
|
|
11 |
class PredisConnector implements Connector
|
|
|
12 |
{
|
|
|
13 |
/**
|
|
|
14 |
* Create a new clustered Predis connection.
|
|
|
15 |
*
|
|
|
16 |
* @param array $config
|
|
|
17 |
* @param array $options
|
|
|
18 |
* @return \Illuminate\Redis\Connections\PredisConnection
|
|
|
19 |
*/
|
|
|
20 |
public function connect(array $config, array $options)
|
|
|
21 |
{
|
|
|
22 |
$formattedOptions = array_merge(
|
|
|
23 |
['timeout' => 10.0], $options, Arr::pull($config, 'options', [])
|
|
|
24 |
);
|
|
|
25 |
|
|
|
26 |
if (isset($config['prefix'])) {
|
|
|
27 |
$formattedOptions['prefix'] = $config['prefix'];
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
return new PredisConnection(new Client($config, $formattedOptions));
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Create a new clustered Predis connection.
|
|
|
35 |
*
|
|
|
36 |
* @param array $config
|
|
|
37 |
* @param array $clusterOptions
|
|
|
38 |
* @param array $options
|
|
|
39 |
* @return \Illuminate\Redis\Connections\PredisClusterConnection
|
|
|
40 |
*/
|
|
|
41 |
public function connectToCluster(array $config, array $clusterOptions, array $options)
|
|
|
42 |
{
|
|
|
43 |
$clusterSpecificOptions = Arr::pull($config, 'options', []);
|
|
|
44 |
|
|
|
45 |
if (isset($config['prefix'])) {
|
|
|
46 |
$clusterSpecificOptions['prefix'] = $config['prefix'];
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
return new PredisClusterConnection(new Client(array_values($config), array_merge(
|
|
|
50 |
$options, $clusterOptions, $clusterSpecificOptions
|
|
|
51 |
)));
|
|
|
52 |
}
|
|
|
53 |
}
|