Ejemplo n.º 1
0
 /**
  * @return Observable\AnonymousObservable
  */
 protected function createSocketForAddress()
 {
     $this->context = stream_context_create($this->contextParams);
     return parent::createSocketForAddress();
 }
Ejemplo n.º 2
0
 /**
  * @param $host
  * @param string $masterName
  * @return AnonymousObservable
  */
 public function connectSentinel($host, $masterName = 'mymaster')
 {
     list($host, $port) = explode(':', $host);
     $connector = new Tcp($this->loop);
     return $connector->connect($host, $port)->flatMap(function (ConnectorEvent $event) use($masterName) {
         $stream = $event->getStream();
         // tweak for stream select
         $stream = new RedisStream($stream->getSocket(), $this->loop);
         $stream->write("SENTINEL get-master-addr-by-name {$masterName} \r\n");
         return $stream;
     })->flatMap(function (StreamEvent $event) use($connector) {
         $parser = new ResponseParser();
         $data = $parser->pushIncoming($event->getData());
         $data = $data[0]->getValueNative();
         $connector->disconnect();
         return $this->connect("{$data[0]}:{$data[1]}");
     });
 }