MultiBulkResponseIterator now implements the Countable interface.

This commit is contained in:
Daniele Alessandri
2010-02-25 12:41:57 +01:00
parent b7203d97e7
commit a1aaf73b78
+8 -1
View File
@@ -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);
}