Skip to content

Commit

Permalink
Merge pull request #7 from krissss/main
Browse files Browse the repository at this point in the history
Support prefix
  • Loading branch information
walkor committed Jun 21, 2022
2 parents 4c900f8 + f20f25e commit d0491c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected static function connect($config)
if (!extension_loaded('redis')) {
throw new \RuntimeException('Please make sure the PHP Redis extension is installed and enabled.');
}

$redis = new RedisConnection();
$address = $config['host'];
$config = [
Expand All @@ -60,6 +60,7 @@ protected static function connect($config)
'auth' => $config['options']['auth'] ?? '',
'timeout' => $config['options']['timeout'] ?? 2,
'ping' => $config['options']['ping'] ?? 55,
'prefix' => $config['options']['prefix'] ?? '',
];
$redis->connectWithConfig($config);
return $redis;
Expand Down
5 changes: 4 additions & 1 deletion src/RedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class RedisConnection extends \Redis
{
/**
* @var array
* @var array
*/
protected $config = [];

Expand All @@ -42,6 +42,9 @@ public function connectWithConfig(array $config = [])
if (!empty($this->config['db'])) {
$this->select($this->config['db']);
}
if (!empty($this->config['prefix'])) {
$this->setOption(\Redis::OPT_PREFIX, $this->config['prefix']);
}
if (Worker::getAllWorkers() && !$timer) {
$timer = Timer::add($this->config['ping'] ?? 55, function () {
$this->execCommand('ping');
Expand Down
1 change: 1 addition & 0 deletions src/config/plugin/webman/redis-queue/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'options' => [
'auth' => null, // 密码,字符串类型,可选参数
'db' => 0, // 数据库
'prefix' => '', // key 前缀
'max_attempts' => 5, // 消费失败后,重试次数
'retry_seconds' => 5, // 重试间隔,单位秒
]
Expand Down

0 comments on commit d0491c3

Please sign in to comment.