1 | <?php |
||
21 | class PhpRedisConnector extends BasePhpRedisConnector |
||
22 | { |
||
23 | /** |
||
24 | * Create the Redis client instance. |
||
25 | * |
||
26 | * @param array $config |
||
27 | * @return \Redis |
||
28 | */ |
||
29 | 1 | protected function createClient(array $config) |
|
30 | { |
||
31 | return tap(new Redis(), function (Redis $client) use ($config) { |
||
32 | 1 | $this->establishConnection($client, $config); |
|
33 | |||
34 | 1 | if (! empty($config['password'])) { |
|
35 | $client->auth((string) $config['password']); |
||
36 | } |
||
37 | |||
38 | 1 | if (! empty($config['database'])) { |
|
39 | 1 | $client->select((int) $config['database']); |
|
40 | } |
||
41 | |||
42 | 1 | if (! empty($config['prefix'])) { |
|
43 | 1 | $client->setOption(Redis::OPT_PREFIX, (string) $config['prefix']); |
|
44 | } |
||
45 | |||
46 | 1 | if (! empty($config['read_timeout'])) { |
|
47 | 1 | $client->setOption(Redis::OPT_READ_TIMEOUT, (string) $config['read_timeout']); |
|
48 | } |
||
49 | |||
50 | 1 | if (! empty($config['serializer'])) { |
|
51 | 1 | $serializer = $this->getSerializerFromConfig($config['serializer']); |
|
52 | 1 | $client->setOption(Redis::OPT_SERIALIZER, (string) $serializer); |
|
53 | } |
||
54 | |||
55 | 1 | if (! empty($config['scan'])) { |
|
56 | $client->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); |
||
57 | } |
||
58 | 1 | }); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Create a new clustered PhpRedis connection. |
||
63 | * |
||
64 | * @param array $config |
||
65 | * @param array $clusterOptions |
||
66 | * @param array $options |
||
67 | * @return \Illuminate\Redis\Connections\PhpRedisClusterConnection |
||
68 | */ |
||
69 | public function connectToCluster(array $config, array $clusterOptions, array $options) |
||
70 | { |
||
71 | $options = array_merge($options, $clusterOptions, Arr::pull($config, 'options', [])); |
||
72 | |||
73 | // Use native Redis clustering |
||
74 | if (Arr::get($options, 'cluster') === 'redis') { |
||
75 | return new PhpRedisClusterConnection($this->createRedisClusterInstance( |
||
76 | array_map([$this, 'buildClusterConnectionString'], $config), |
||
77 | $options |
||
78 | )); |
||
79 | } |
||
80 | |||
81 | // Use client-side sharding |
||
82 | return new PhpRedisClusterConnection($this->createRedisArrayInstance( |
||
|
|||
83 | array_map([$this, 'buildRedisArrayConnectionString'], $config), |
||
84 | $options |
||
85 | )); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Build a PhpRedis hosts array. |
||
90 | * |
||
91 | * @param array $server |
||
92 | * @return string |
||
93 | */ |
||
94 | protected function buildRedisArrayConnectionString(array $server) |
||
98 | |||
99 | /** |
||
100 | * Create a new redis array instance. |
||
101 | * |
||
102 | * @param array $servers |
||
103 | * @param array $options |
||
104 | * @return \RedisArray |
||
105 | */ |
||
106 | protected function createRedisArrayInstance(array $servers, array $options) |
||
142 | |||
143 | /** |
||
144 | * Resolve serializer |
||
145 | * |
||
146 | * @param string $serializer |
||
147 | * @return int |
||
148 | * @throws \InvalidArgumentException |
||
149 | */ |
||
150 | 1 | protected function getSerializerFromConfig(string $serializer): int |
|
169 | } |
||
170 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: