MultiBulkResponseTuple.php 736 B

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