SDK
SDK Javascript v5.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](/sdk/js/5/core-classes/kuzzle/query)

[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 #

// Using callbacks (NodeJS or Web Browser)
kuzzle.memoryStorage.sort('key', function (err, values) {
  // callback called once the action has completed
});
// Using promises (NodeJS only)
kuzzle.memoryStorage.sortPromise('key')
  .then(values => {
    // resolved once the action has completed
  });

Callback response:

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