46 lines
1 KiB
PHP
46 lines
1 KiB
PHP
<?php
|
|
|
|
namespace core\log\client;
|
|
|
|
/**
|
|
* Redis stream (only https://github.com/phpredis/phpredis for now)
|
|
*/
|
|
class Redis
|
|
{
|
|
/**
|
|
* Client object for redis
|
|
*
|
|
* @var \Redis
|
|
*/
|
|
protected \Redis $client;
|
|
|
|
/**
|
|
* @throws \core\config\ConfigException
|
|
*/
|
|
public function __construct(config: \core\config\Configuration $configuration, tag: \core\log\Tag $tag)
|
|
{
|
|
$this->configuration = $configuration;
|
|
$this->tag = $tag;
|
|
$config = array(
|
|
'host' => $this->configuration.get('hostname'),
|
|
'port' => $this->configuration.get('port'), // -1 if socket
|
|
);
|
|
if ($this->configuration.exist('auth'))
|
|
{
|
|
$config['auth'] = array();
|
|
if ($this->configuration.exist('auth', 'username'))
|
|
{
|
|
$config['auth'][] = $this->configuration.get('auth', 'username');
|
|
}
|
|
$config['auth'][] = $this->configuration.get('auth', 'password');
|
|
}
|
|
$this->client = new \Redis($config);
|
|
}
|
|
|
|
public function push(event: \core\log\Event $event) : \core\log\Event
|
|
{
|
|
$this->client->rpush($tag->generate_id(), $event->display());
|
|
}
|
|
}
|
|
|
|
?>
|