Rewrite the logic used to handle Redis commands with clustering.

The reason for this change is to support the upcoming redis-cluster since
it has different behaviors compared to the client-side cluster implementation
provided by Predis. For example redis-cluster will not support key tags or
certain operations currently available with our client-side implementation.
This commit is contained in:
Daniele Alessandri
2012-02-25 15:27:20 +01:00
parent 56a3e327fc
commit 511fe0bbab
55 changed files with 653 additions and 543 deletions
+4 -42
View File
@@ -11,8 +11,6 @@
namespace Predis\Command;
use Predis\Helpers;
use Predis\Distribution\HashGeneratorInterface;
/**
* Base class for Redis commands.
@@ -76,57 +74,21 @@ abstract class AbstractCommand implements CommandInterface
}
/**
* Checks if the command can return an hash for client-side sharding.
*
* @return Boolean
* {@inheritdoc}
*/
protected function canBeHashed()
public function setHash($hash)
{
return isset($this->arguments[0]);
}
/**
* Checks if the specified array of keys will generate the same hash.
*
* @param array $keys Array of keys.
* @return Boolean
*/
protected function checkSameHashForKeys(Array $keys)
{
if (($count = count($keys)) === 0) {
return false;
}
$currentKey = Helpers::extractKeyTag($keys[0]);
for ($i = 1; $i < $count; $i++) {
$nextKey = Helpers::extractKeyTag($keys[$i]);
if ($currentKey !== $nextKey) {
return false;
}
$currentKey = $nextKey;
}
return true;
$this->hash = $hash;
}
/**
* {@inheritdoc}
*/
public function getHash(HashGeneratorInterface $hasher)
public function getHash()
{
if (isset($this->hash)) {
return $this->hash;
}
if ($this->canBeHashed()) {
$key = Helpers::extractKeyTag($this->arguments[0]);
$this->hash = $hasher->hash($key);
return $this->hash;
}
return null;
}
/**