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) |
|
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 | 1 | public function connectToCluster(array $config, array $clusterOptions, array $options) |
|
70 | { |
||
71 | 1 | $options = array_merge($options, $clusterOptions, Arr::pull($config, 'options', [])); |
|
72 | |||
73 | // Use native Redis clustering |
||
74 | 1 | 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 | 1 | return new PhpRedisClusterConnection($this->createRedisArrayInstance( |
|
|
|||
83 | 1 | 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 | 1 | protected function buildRedisArrayConnectionString(array $server) |
|
95 | { |
||
96 | 1 | return $server['host'] . ':' . $server['port']; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * Create a new redis array instance. |
||
101 | * |
||
102 | * @param array $servers |
||
103 | * @param array $options |
||
104 | * @return \RedisArray |
||
105 | */ |
||
106 | 1 | protected function createRedisArrayInstance(array $servers, array $options) |
|
107 | { |
||
108 | 1 | $client = new RedisArray($servers, Arr::only($options, [ |
|
109 | 1 | 'function', |
|
110 | 'previous', |
||
111 | 'retry_interval', |
||
112 | 'lazy_connect', |
||
113 | 'connect_timeout', |
||
114 | 'read_timeout', |
||
115 | 'algorithm', |
||
116 | 'consistent', |
||
117 | 'distributor', |
||
118 | ])); |
||
119 | |||
120 | 1 | if (! empty($options['password'])) { |
|
121 | // @TODO: Remove after this will be implemented |
||
122 | // https://github.com/phpredis/phpredis/issues/1508 |
||
123 | throw new InvalidArgumentException('RedisArray does not support authorization'); |
||
124 | //$client->auth((string) $options['password']); |
||
125 | } |
||
126 | |||
127 | 1 | if (! empty($options['database'])) { |
|
128 | 1 | $client->select((int) $options['database']); |
|
129 | } |
||
130 | |||
131 | 1 | if (! empty($options['prefix'])) { |
|
132 | 1 | $client->setOption(Redis::OPT_PREFIX, (string) $options['prefix']); |
|
133 | } |
||
134 | |||
135 | 1 | if (! empty($options['serializer'])) { |
|
136 | 1 | $serializer = $this->getSerializerFromConfig($options['serializer']); |
|
137 | 1 | $client->setOption(Redis::OPT_SERIALIZER, (string) $serializer); |
|
138 | } |
||
139 | |||
140 | 1 | return $client; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * Resolve serializer |
||
145 | * |
||
146 | * @param string $serializer |
||
147 | * @return int |
||
148 | * @throws \InvalidArgumentException |
||
149 | */ |
||
150 | 2 | 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: