Move the key-tag extractor method to Predis\Helpers.

This commit is contained in:
Daniele Alessandri
2011-04-24 11:04:17 +02:00
parent b396eb3c48
commit 4ef8948b5e
2 changed files with 15 additions and 14 deletions
+4 -14
View File
@@ -2,6 +2,7 @@
namespace Predis\Commands;
use Predis\Helpers;
use Predis\Distribution\INodeKeyGenerator;
abstract class Command implements ICommand {
@@ -31,24 +32,13 @@ abstract class Command implements ICommand {
return isset($this->_arguments[0]);
}
protected function getHashablePart($key) {
$start = strpos($key, '{');
if ($start !== false) {
$end = strpos($key, '}', $start);
if ($end !== false) {
$key = substr($key, ++$start, $end - $start);
}
}
return $key;
}
protected function checkSameHashForKeys(Array $keys) {
if (($count = count($keys)) === 0) {
return false;
}
$currentKey = $this->getHashablePart($keys[0]);
$currentKey = Helpers::getKeyHashablePart($keys[0]);
for ($i = 1; $i < $count; $i++) {
$nextKey = $this->getHashablePart($keys[$i]);
$nextKey = Helpers::getKeyHashablePart($keys[$i]);
if ($currentKey !== $nextKey) {
return false;
}
@@ -62,7 +52,7 @@ abstract class Command implements ICommand {
return $this->_hash;
}
if ($this->canBeHashed()) {
$key = $this->getHashablePart($this->_arguments[0]);
$key = Helpers::getKeyHashablePart($this->_arguments[0]);
$this->_hash = $distributor->generateKey($key);
return $this->_hash;
}
+11
View File
@@ -33,4 +33,15 @@ class Helpers {
}
return $arguments;
}
public static function getKeyHashablePart($key) {
$start = strpos($key, '{');
if ($start !== false) {
$end = strpos($key, '}', $start);
if ($end !== false) {
$key = substr($key, ++$start, $end - $start);
}
}
return $key;
}
}