|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Laravel Lodash package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Longman\LaravelLodash\Redis\Connectors; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Redis\Connectors\PhpRedisConnector as BasePhpRedisConnector; |
|
15
|
|
|
use Redis; |
|
16
|
|
|
|
|
17
|
|
|
class PhpRedisConnector extends BasePhpRedisConnector |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Create the Redis client instance. |
|
21
|
|
|
* |
|
22
|
|
|
* @param array $config |
|
23
|
|
|
* @return \Redis |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function createClient(array $config) |
|
26
|
|
|
{ |
|
27
|
|
|
return tap(new Redis, function ($client) use ($config) { |
|
28
|
|
|
$this->establishConnection($client, $config); |
|
29
|
|
|
|
|
30
|
|
|
if (! empty($config['password'])) { |
|
31
|
|
|
$client->auth($config['password']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (! empty($config['database'])) { |
|
35
|
|
|
$client->select($config['database']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (! empty($config['prefix'])) { |
|
39
|
|
|
$client->setOption(Redis::OPT_PREFIX, $config['prefix']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (! empty($config['read_timeout'])) { |
|
43
|
|
|
$client->setOption(Redis::OPT_READ_TIMEOUT, $config['read_timeout']); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (! empty($config['serializer'])) { |
|
47
|
|
|
$serializer = 0; |
|
48
|
|
|
switch ($config['serializer']) { |
|
49
|
|
|
case 'igbinary': |
|
50
|
|
|
$serializer = Redis::SERIALIZER_IGBINARY; |
|
51
|
|
|
break; |
|
52
|
|
|
case 'php': |
|
53
|
|
|
$serializer = Redis::SERIALIZER_PHP; |
|
54
|
|
|
break; |
|
55
|
|
|
} |
|
56
|
|
|
$client->setOption(Redis::OPT_SERIALIZER, (string) $serializer); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (! empty($config['scan'])) { |
|
60
|
|
|
$client->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); |
|
61
|
|
|
} |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|