Prechádzať zdrojové kódy

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

Daniele Alessandri 15 rokov pred
rodič
commit
a84c9bdac7
1 zmenil súbory, kde vykonal 5 pridanie a 1 odobranie
  1. 5 1
      lib/Predis.php

+ 5 - 1
lib/Predis.php

@@ -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);
     }