ConnectionCluster now implements the IteratorAggregate interface, thus enabling iterations over the registered connections simply by using a foreach loop.

This commit is contained in:
Daniele Alessandri
2009-12-14 17:43:30 +01:00
parent 755c252fde
commit a84c9bdac7
+5 -1
View File
@@ -717,7 +717,7 @@ class Connection implements IConnection {
}
}
class ConnectionCluster implements IConnection {
class ConnectionCluster implements IConnection, \IteratorAggregate {
// TODO: storing a temporary map of commands hashes to hashring items (that
// is, connections) could offer a notable speedup, but I am wondering
// about the increased memory footprint.
@@ -778,6 +778,10 @@ class ConnectionCluster implements IConnection {
return $this->_pool[$id === null ? 0 : $id];
}
public function getIterator() {
return new \ArrayIterator($this->_pool);
}
public function writeCommand(Command $command) {
$this->getConnection($command)->writeCommand($command);
}