Skip to content

Commit 0f0895f

Browse files
committed
add
1 parent 7a15c45 commit 0f0895f

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/Driver/RedisDriver.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
use MixPlus\Queue\JobInterface;
66
use MixPlus\Queue\JobMessage;
77
use MixPlus\Queue\MessageInterface;
8-
use Redis;
98
use RuntimeException;
109

1110
class RedisDriver extends Driver
1211
{
1312
/**
14-
* @var Redis
13+
* @var \Mix\Redis\Redis
1514
*/
1615
protected $redis;
1716

@@ -45,38 +44,31 @@ public function __construct($config = [], $listener = [])
4544
$this->timeout = 5;
4645
$this->retrySeconds = 10;
4746
$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']);
4949
}
5050

5151
private function initRedis()
5252
{
5353
$options = [
54-
'expire' => 60,
5554
'default' => 'default',
5655
'host' => '127.0.0.1',
5756
'port' => '6379',
5857
'password' => '',
5958
'select' => 0,
6059
'timeout' => 0,
61-
'persistent' => false,
6260
];
6361
if (!empty($this->config)) {
6462
$this->config = array_merge($options, $this->config);
6563
}
6664
if (!extension_loaded('redis')) {
6765
throw new RuntimeException('redis扩展未安装');
6866
}
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);
8072
}
8173

8274
public function push(JobInterface $job, int $delay = 0): bool

0 commit comments

Comments
 (0)