Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Apr 27, 2023
1 parent b9a3913 commit 1e68e67
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/reporter/RedisReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ public static function __make($name, $config)
public function __construct($config)
{
$this->config = array_merge([
'persistent' => true,
'host' => 'localhost',
'port' => 6379,
'timeout' => 0,
'password' => '',
'select' => 0,
'host' => 'localhost',
'port' => 6379,
'timeout' => 10,
], $config);

$this->client = $this->createClient();
Expand All @@ -47,18 +44,25 @@ public function __construct($config)
protected function createClient()
{
$config = $this->config;
$func = $config['persistent'] ? 'pconnect' : 'connect';

$client = new Redis;
$client->$func($config['host'], $config['port'], $config['timeout']);
$ret = $client->connect($config['host'], $config['port'], $config['timeout']);

if ('' != $config['password']) {
$client->auth($config['password']);
if ($ret === false) {
throw new \RuntimeException(sprintf('Failed to connect Redis server: %s', $client->getLastError()));
}

if (0 != $config['select']) {
$client->select($config['select']);
if (isset($config['password'])) {
$config['password'] = (string) $config['password'];
if ($config['password'] !== '') {
$client->auth($config['password']);
}
}

if (isset($config['database'])) {
$client->select($config['database']);
}

return $client;
}

Expand Down

0 comments on commit 1e68e67

Please # to comment.