|
5 | 5 | use MixPlus\Queue\JobInterface; |
6 | 6 | use MixPlus\Queue\JobMessage; |
7 | 7 | use MixPlus\Queue\MessageInterface; |
8 | | -use Redis; |
9 | 8 | use RuntimeException; |
10 | 9 |
|
11 | 10 | class RedisDriver extends Driver |
12 | 11 | { |
13 | 12 | /** |
14 | | - * @var Redis |
| 13 | + * @var \Mix\Redis\Redis |
15 | 14 | */ |
16 | 15 | protected $redis; |
17 | 16 |
|
@@ -45,38 +44,31 @@ public function __construct($config = [], $listener = []) |
45 | 44 | $this->timeout = 5; |
46 | 45 | $this->retrySeconds = 10; |
47 | 46 | $this->handleTimeout = 10; |
48 | | - $this->channel = make(ChannelConfig::class, ['channel' => $config['default'] . ':queues']); |
| 47 | + $default = $config['default'] ?? 'default'; |
| 48 | + $this->channel = make(ChannelConfig::class, ['channel' => $default . ':queues']); |
49 | 49 | } |
50 | 50 |
|
51 | 51 | private function initRedis() |
52 | 52 | { |
53 | 53 | $options = [ |
54 | | - 'expire' => 60, |
55 | 54 | 'default' => 'default', |
56 | 55 | 'host' => '127.0.0.1', |
57 | 56 | 'port' => '6379', |
58 | 57 | 'password' => '', |
59 | 58 | 'select' => 0, |
60 | 59 | 'timeout' => 0, |
61 | | - 'persistent' => false, |
62 | 60 | ]; |
63 | 61 | if (!empty($this->config)) { |
64 | 62 | $this->config = array_merge($options, $this->config); |
65 | 63 | } |
66 | 64 | if (!extension_loaded('redis')) { |
67 | 65 | throw new RuntimeException('redis扩展未安装'); |
68 | 66 | } |
69 | | - $func = $this->config['persistent'] ? 'pconnect' : 'connect'; |
70 | | - $this->redis = new Redis(); |
71 | | - $this->redis->{$func}($this->config['host'], $this->config['port'], $this->config['timeout']); |
72 | | - |
73 | | - if ($this->config['password'] != '') { |
74 | | - $this->redis->auth($this->config['password']); |
75 | | - } |
76 | | - |
77 | | - if ($this->config['select'] != 0) { |
78 | | - $this->redis->select($this->config['select']); |
79 | | - } |
| 67 | + $this->redis = new \Mix\Redis\Redis($this->config['host'], |
| 68 | + $this->config['port'], |
| 69 | + $this->config['password'], |
| 70 | + $this->config['select'] ?? $this->config['db'] ?? 0, |
| 71 | + $this->config['timeout'] ?? 0); |
80 | 72 | } |
81 | 73 |
|
82 | 74 | public function push(JobInterface $job, int $delay = 0): bool |
|
0 commit comments