SDK
SDK Javascript v6.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.

[Redis documentation]

Arguments #

sort(key, [options]);

ArgumentsTypeDescription
key
string
List, set or sorted set key
options
object
Optional query arguments

options #

The options arguments can contain the following option properties:

PropertyType (default)Description
alpha
boolean (false)
Performs an alphanumerical sort instead of a numeric one
by
string
Instead of sorting by values, sorts by values contained in external keys, using the provided pattern completed by values of the list/set/sorted set to sort
direction
string ('ASC')
Sorts in ascendant or descendant order.
Allowed values: ASC, DESC
get
string[]
Instead of returning the sorted values directly, returns the values contained in external keys, using patterns completed by the sorted values
limit
integer[]
Limits the result set to a range of matching elements (similar to SELECT LIMIT offset, count in SQL).
Format: [<offset(int)>, <count(int)>]
queuable
boolean (true)
If true, queues the request during downtime, until connected to Kuzzle again

Resolve #

Resolves to the sorted elements.

Usage #

try {
  await kuzzle.ms.sadd('setfoo', [1, 2, 3, 4, 5, 6, 7]);
  await kuzzle.ms.rpush('listfoo', ['foo', 'bar', 'baz', 'qux']);
  // Prints: [ '7', '6', '5', '4', '3', '2', '1' ]
  console.log(await kuzzle.ms.sort('setfoo', {direction: 'DESC'}));
  // Prints: [ 'bar', 'baz', 'foo', 'qux' ]
  console.log(await kuzzle.ms.sort('listfoo', {alpha: true}));
} catch (error) {
  console.error(error.message);
}