mirror of
https://github.com/predis/predis.git
synced 2026-09-05 15:42:31 +00:00
ZRANGE, ZREVRANGE and ZRANGEBYSCORE accepts an array instance for optional modifiers.
This commit is contained in:
+33
-11
@@ -2566,20 +2566,42 @@ class ZSetIntersectionStore extends \Predis\Commands\ZSetUnionStore {
|
||||
}
|
||||
|
||||
class ZSetRange extends \Predis\MultiBulkCommand {
|
||||
private $_withScores = false;
|
||||
public function getCommandId() { return 'ZRANGE'; }
|
||||
public function parseResponse($data) {
|
||||
$arguments = $this->getArguments();
|
||||
public function filterArguments(Array $arguments) {
|
||||
if (count($arguments) === 4) {
|
||||
if (strtolower($arguments[3]) === 'withscores') {
|
||||
if ($data instanceof \Iterator) {
|
||||
return new \Predis\Shared\MultiBulkResponseKVIterator($data);
|
||||
}
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$result[] = array($data[$i], $data[++$i]);
|
||||
}
|
||||
return $result;
|
||||
$lastType = gettype($arguments[3]);
|
||||
if ($lastType === 'string' && strtolower($arguments[3]) === 'withscores') {
|
||||
// used for compatibility with older versions
|
||||
$arguments[3] = array('WITHSCORES' => true);
|
||||
$lastType = 'array';
|
||||
}
|
||||
if ($lastType === 'array') {
|
||||
$options = $this->prepareOptions(array_pop($arguments));
|
||||
return array_merge($arguments, $options);
|
||||
}
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
protected function prepareOptions($options) {
|
||||
$opts = array_change_key_case($options, CASE_UPPER);
|
||||
$finalizedOpts = array();
|
||||
if (isset($opts['WITHSCORES'])) {
|
||||
$finalizedOpts[] = 'WITHSCORES';
|
||||
$this->_withScores = true;
|
||||
}
|
||||
return $finalizedOpts;
|
||||
}
|
||||
public function parseResponse($data) {
|
||||
if ($this->_withScores) {
|
||||
if ($data instanceof \Iterator) {
|
||||
return new \Predis\Shared\MultiBulkResponseKVIterator($data);
|
||||
}
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$result[] = array($data[$i], $data[++$i]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user