Forráskód Böngészése

MultiBulkResponseIterator now implements the Countable interface.

Daniele Alessandri 15 éve
szülő
commit
a1aaf73b78
1 módosított fájl, 8 hozzáadás és 1 törlés
  1. 8 1
      lib/Predis.php

+ 8 - 1
lib/Predis.php

@@ -1129,7 +1129,7 @@ class HashRing {
     }
 }
 
-class MultiBulkResponseIterator implements \Iterator {
+class MultiBulkResponseIterator implements \Iterator, \Countable {
     private $_connection, $_position, $_current, $_replySize;
 
     public function __construct($socket, $size) {
@@ -1176,6 +1176,13 @@ class MultiBulkResponseIterator implements \Iterator {
         return $this->_position < $this->_replySize;
     }
 
+    public function count() {
+        // NOTE: use count if you want to get the size of the current multi-bulk 
+        //       response without using iterator_count (which actually consumes 
+        //       our iterator to calculate the size, and we cannot perform a rewind)
+        return $this->_replySize;
+    }
+
     private function getValue() {
         return \Predis\Response::read($this->_connection);
     }