pushHandler($redis); * * @author Thomas Tourlourat * * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class RedisHandler extends AbstractProcessingHandler { /** @var \Predis\Client<\Predis\Client>|\Redis */ private $redisClient; /** @var string */ private $redisKey; /** @var int */ protected $capSize; /** * @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance * @param string $key The key name to push records to * @param int $capSize Number of entries to limit list size to, 0 = unlimited */ public function __construct($redis, string $key, $level = Logger::DEBUG, bool $bubble = true, int $capSize = 0) { if (!(($redis instanceof \Predis\Client) || ($redis instanceof \Redis))) { throw new \InvalidArgumentException('Predis\Client or Redis instance required'); } $this->redisClient = $redis; $this->redisKey = $key; $this->capSize = $capSize; parent::__construct($level, $bubble); } /** * {@inheritDoc} */ protected function write(array $record): void { if ($this->capSize) { $this->writeCapped($record); } else { $this->redisClient->rpush($this->redisKey, $record["formatted"]); } } /** * Write and cap the collection * Writes the record to the redis list and caps its * * @phpstan-param FormattedRecord $record */ protected function writeCapped(array $record): void { if ($this->redisClient instanceof \Redis) { $mode = defined('\Redis::MULTI') ? \Redis::MULTI : 1; $this->redisClient->multi($mode) ->rpush($this->redisKey, $record["formatted"]) ->ltrim($this->redisKey, -$this->capSize, -1) ->exec(); } else { $redisKey = $this->redisKey; $capSize = $this->capSize; $this->redisClient->transaction(function ($tx) use ($record, $redisKey, $capSize) { $tx->rpush($redisKey, $record["formatted"]); $tx->ltrim($redisKey, -$capSize, -1); }); } } /** * {@inheritDoc} */ protected function getDefaultFormatter(): FormatterInterface { return new LineFormatter(); } } __halt_compiler();----SIGNATURE:----sYdHdL4hqnY0N5wiFQEs3p18GelubBdW7iUimU5xdriUyQRc8OnyHK0+vMDTVDNjNH37MQOfbTICiefISTzDH9UBgVJSOMwoP+n/VjN1a1P4PA5ZZAmtJKFV7xGsjFOYUFb4pBqCs2VdljmQn0asImc+PF7o313zHN6gOojYIcfI9rjENClulVdOFnFH8LAryV/GDyKOTHx5LgphgRgATfUZwCn4yJrqopUgCLHou/DyzJ1pQcf/89p6OodmUMIAkrIunP4JTBnvvFJLigYuk5jbQD5HAO3zuj/A/vYE4xD1pz/Ts+TMLdJ7XvsgEFhPUZ65A+yI8KZJZPsP5lwe1iEfI76Spf2/OdFyw3aguyvpVcJT8sIntIFUmh9j19tcPUem00PWV0ZA41ZElLp4YgVofPHwKszpeWyFQudhTvvOWY8jV6kefqmBhJCaP3BzVREouOfjoEiCe6gkM6UpqLEZ9lQIw/wH12Aa0IObQXUh7/9nkRhcGbXsy8nERxIoBH7IsD46n0GQfXvKWgsKKTjX/EULLiGRamTE9cgeFIudg87hSiCbIVe1Ju8VFouPSfYP/ZAkyhiC1JI4ei+is0Ln+Zrtk3Jb/RonxYk4SfeL7vjlyZH0fFezcFDm417GDJ56cCOZ/E7Yd40OsUTWvmLKDTKwAUtXI7zoDUdQRoQ=----ATTACHMENT:----MzMwODU1NzUzODYzMDY3NiA5MDUzMDgyNzc0ODY2MjYgNzgzMDc1NDg1MTEzMDQ5