Пример #1
0
 /**
  * @param MultiMode $mode
  * @return bool
  */
 protected function startMulti(MultiMode $mode)
 {
     // we have to override this method and make sure it only calls our active connection
     $conn = $this->getWrappedRedis(__FUNCTION__);
     // this next line is not really clean, if we ever add more modes, we need to rework it
     $res = $mode->equals(MultiMode::MULTI) ? $conn->multi() : ($mode->equals(MultiMode::PIPELINE) ? $conn->pipeline() : $conn->stream());
     if (!$res) {
         return false;
     }
     // let's reset the internal variables
     $this->inMultiMode = true;
     return true;
 }
Пример #2
0
 /**
  * This method initiates the multi/pipeline mode on all connections. It is here to avoid code duplication
  * in multi() and pipeline().
  *
  * @param MultiMode $mode which mode to start
  * @throws MultiModeException if an error occurs during multi
  * @throws InvalidArgumentException if an unknown mode is passed
  * @return bool
  */
 protected function startMulti(MultiMode $mode)
 {
     try {
         foreach ($this->connections as $conn) {
             $res = null;
             switch ($mode->val()) {
                 case MultiMode::MULTI:
                     $res = $conn->getClient()->multi();
                     break;
                 case MultiMode::PIPELINE:
                     $res = $conn->getClient()->pipeline();
                     break;
                 case MultiMode::STREAM:
                     $res = $conn->getClient()->stream();
                     break;
                 default:
                     throw new InvalidArgumentException('unknown multi mode ' . $mode);
             }
             // if starting multi mode fails for some reason, we cancel it again for all other instances
             if (!$res) {
                 throw new MultiModeException('could not start multi mode on ' . $conn->getName());
             }
         }
     } catch (MultiModeException $e) {
         // this will throw an exception if multi was not active yet, so we force the commands
         $this->discard(true);
         throw $e;
     }
     // let's reset the internal variables
     $this->inMultiMode = true;
     // in stream mode we don't need to return the results
     $this->trackingActive = !$mode->equals(MultiMode::STREAM);
     $this->multiModeTracking = array();
     return true;
 }
Пример #3
0
 /**
  * Helper method which starts multi mode.
  *
  * @param MultiMode $mode
  * @return bool
  */
 private function startMultiMode(MultiMode $mode)
 {
     $nativeMode = null;
     // didn't know that it's possible to call switch on an object
     switch ($mode) {
         case MultiMode::STREAM():
             // as we don't have much influence into what the phpredis extension does during pipeline mode
             // we just treat stream mode as regular pipeline mode, but set the variable
         // as we don't have much influence into what the phpredis extension does during pipeline mode
         // we just treat stream mode as regular pipeline mode, but set the variable
         case MultiMode::PIPELINE():
             $nativeMode = \Redis::PIPELINE;
             break;
         case MultiMode::MULTI():
             $nativeMode = \Redis::MULTI;
             break;
     }
     $ret = $this->redis->multi($nativeMode);
     if (!$ret) {
         return false;
     }
     $this->inMultiMode = true;
     $this->isStreamMode = $mode->equals(MultiMode::STREAM);
     return true;
 }