From 880d2d24b9545e95d4bdb491b5b309ce6df7d2d4 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 24 Apr 2011 11:04:57 +0200 Subject: [PATCH] Add the ability to get a connection out of a cluster using a key. --- lib/Predis/Network/ConnectionCluster.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Predis/Network/ConnectionCluster.php b/lib/Predis/Network/ConnectionCluster.php index 91167632..d4d5d831 100644 --- a/lib/Predis/Network/ConnectionCluster.php +++ b/lib/Predis/Network/ConnectionCluster.php @@ -2,6 +2,7 @@ namespace Predis\Network; +use Predis\Helpers; use Predis\ClientException; use Predis\Commands\ICommand; use Predis\Distribution\IDistributionStrategy; @@ -61,6 +62,12 @@ class ConnectionCluster implements IConnectionCluster, \IteratorAggregate { return isset($this->_pool[$alias]) ? $this->_pool[$alias] : null; } + public function getConnectionByKey($key) { + $hashablePart = Helpers::getKeyHashablePart($key); + $keyHash = $this->_distributor->generateKey($hashablePart); + return $this->_distributor->get($keyHash); + } + public function getIterator() { return new \ArrayIterator($this->_pool); }