SDK
SDK PHP v3.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

sort #

Sorts and returns elements contained in a list, a set of unique values or a sorted set. By default, sorting is numeric and elements are compared by their value interpreted as double precision floating point number.

While Kuzzle's API supports the "store" option for this command, Kuzzle SDK methods do not. To sort and store in the same process, use the query method

[Redis documentation]

sort(key, [options], callback) #

ArgumentsTypeDescription
keystringKey identifier
optionsJSON ObjectOptional parameters
callbackfunctionCallback

Options #

OptionTypeDescriptionDefault
alphabooleanPerform an alphanumerical sort instead of a numeric onefalse
bystringInstead of sorting the values stored at key, use them to complete the provided key pattern, and return the sorted list of values stored in those keys.null
directionstringSort in ascendant (ASC) or descendant (DESC) orderASC
getarraySort the values stored at key but, instead of returning these directly, return the values contained in external keys, using the provided array of patterns completed by the sorted valuesnull
limitarrayLimit the result set to a range of matching elements (similar to SELECT LIMIT offset, count in SQL).
Format: [<offset(int)>, <count(int)>]
null
queuablebooleanMake this request queuable or nottrue

Callback Response #

Returns an array of sorted values.

Usage #

<?php
use \Kuzzle\Kuzzle;
$kuzzle = new Kuzzle('localhost');
try {
  $values = $kuzzle->memoryStorage()->sort('key');
}
catch (ErrorException $e) {
}

Callback response:

["sorted element1", "sorted element2", "..."]