public function __construct($stream, LoopInterface $loop) { parent::__construct($stream, $loop); $this->buffer->on('full-drain', function () { $this->emit('full-drain', array($this)); }); }
public function __construct(LoopInterface $loop, $host = 'localhost', $port = 6379, $database = 0, LoggerInterface $logger = null) { $this->logger = $logger ?? new NullLogger(); $url = 'tcp://' . $host . ':' . $port; $this->stream = stream_socket_client($url, $errno, $errstr, 30, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT); parent::__construct($this->stream, $loop); $this->on('close', function ($chunk) { $this->loop->stop(); echo 'Connection Closed' . PHP_EOL; }); $this->on('error', function ($chunk) { throw new Exception($chunk); }); $this->on('data', function ($chunk) { $this->logger->debug('Data from Redis', ['msg' => $chunk]); foreach ($this->parse($chunk) as $msg) { $type = $msg[0]; $this->emit($type, [$msg[1], $msg[2]]); } }); if ($database > 0) { if (!$this->select($database)) { throw new Exception('Error setting database index'); } } }
public function __construct($file, $mode, $loop) { $fd = fopen($file, $mode); stream_set_blocking($fd, 0); parent::__construct($fd, $loop); $this->buffer = new BufferedSink(); $this->pipe($this->buffer); $this->on('error', function ($reason) { $this->buffer->handleErrorEvent($reason); }); }
public function __construct(LoopInterface $loop) { parent::__construct(STDIN, $loop); }