MultiBulkResponseTuple.php 730 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace Predis\Iterators;
  3. class MultiBulkResponseTuple extends MultiBulkResponse {
  4. private $_iterator;
  5. public function __construct(MultiBulkResponseSimple $iterator) {
  6. $virtualSize = count($iterator) / 2;
  7. $this->_iterator = $iterator;
  8. $this->_position = 0;
  9. $this->_current = $virtualSize > 0 ? $this->getValue() : null;
  10. $this->_replySize = $virtualSize;
  11. }
  12. public function __destruct() {
  13. $this->_iterator->sync();
  14. }
  15. protected function getValue() {
  16. $k = $this->_iterator->current();
  17. $this->_iterator->next();
  18. $v = $this->_iterator->current();
  19. $this->_iterator->next();
  20. return array($k, $v);
  21. }
  22. }