Skip to content

Commit f20f25e

Browse files
committed
Support prefix
1 parent 4c900f8 commit f20f25e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/Redis.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected static function connect($config)
5050
if (!extension_loaded('redis')) {
5151
throw new \RuntimeException('Please make sure the PHP Redis extension is installed and enabled.');
5252
}
53-
53+
5454
$redis = new RedisConnection();
5555
$address = $config['host'];
5656
$config = [
@@ -60,6 +60,7 @@ protected static function connect($config)
6060
'auth' => $config['options']['auth'] ?? '',
6161
'timeout' => $config['options']['timeout'] ?? 2,
6262
'ping' => $config['options']['ping'] ?? 55,
63+
'prefix' => $config['options']['prefix'] ?? '',
6364
];
6465
$redis->connectWithConfig($config);
6566
return $redis;

src/RedisConnection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class RedisConnection extends \Redis
2020
{
2121
/**
22-
* @var array
22+
* @var array
2323
*/
2424
protected $config = [];
2525

@@ -42,6 +42,9 @@ public function connectWithConfig(array $config = [])
4242
if (!empty($this->config['db'])) {
4343
$this->select($this->config['db']);
4444
}
45+
if (!empty($this->config['prefix'])) {
46+
$this->setOption(\Redis::OPT_PREFIX, $this->config['prefix']);
47+
}
4548
if (Worker::getAllWorkers() && !$timer) {
4649
$timer = Timer::add($this->config['ping'] ?? 55, function () {
4750
$this->execCommand('ping');

src/config/plugin/webman/redis-queue/redis.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'options' => [
66
'auth' => null, // 密码,字符串类型,可选参数
77
'db' => 0, // 数据库
8+
'prefix' => '', // key 前缀
89
'max_attempts' => 5, // 消费失败后,重试次数
910
'retry_seconds' => 5, // 重试间隔,单位秒
1011
]

0 commit comments

Comments
 (0)