public function current()
 {
     if ($this->_count === null || $this->_count == 0) {
         throw new Rediska_Connection_Exception('call valid before');
     }
     $response = Rediska_Connection_Exec::readResponseFromConnection($this->_connection);
     if ($this->_callback !== null) {
         $response = call_user_func($this->_callback, $response);
     }
     return $response;
 }
Example #2
0
 /**
  * Get response from connection
  *
  * @param Rediska_Connection $connection
  * @return Rediska_PubSub_Response_Abstract
  */
 protected function _getResponseFromConnection(Rediska_Connection $connection)
 {
     $response = Rediska_Connection_Exec::readResponseFromConnection($connection);
     if ($response === null || $response === true) {
         return null;
     }
     list($type, $channel, $body) = $response;
     if ($this->getRediska()->getOption('namespace') !== '' && strpos($channel, $this->getRediska()->getOption('namespace')) === 0) {
         $channel = substr($channel, strlen($this->getRediska()->getOption('namespace')));
     }
     switch ($type) {
         case self::SUBSCRIBE:
             return new Rediska_PubSub_Response_Subscribe($connection, $channel);
         case self::UNSUBSCRIBE:
             return new Rediska_PubSub_Response_Unsubscribe($connection, $channel);
         case self::MESSAGE:
             $message = $this->getRediska()->getSerializer()->unserialize($body);
             return new Rediska_PubSub_Response_Message($connection, $channel, $message);
         default:
             throw new Rediska_PubSub_Response_Exception('Unknown reponse type: ' . $type);
     }
 }
Example #3
0
 /**
  * Get response from connection
  *
  * @param Rediska_Connection $connection
  * @return array|null
  */
 protected function _getResponseFromConnection(Rediska_Connection $connection)
 {
     $response = Rediska_Connection_Exec::readResponseFromConnection($connection);
     if ($response === null || $response === true) {
         return null;
     }
     $timestampAndCommand = explode(' ', $response, 2);
     $command = $timestampAndCommand[1];
     if ($command == '"MONITOR"') {
         return null;
     }
     return $timestampAndCommand;
 }