SDK PHP v3.x

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

Arguments Type Description
key string Key identifier
options JSON Object Optional parameters
callback function Callback

Options #

Option Type Description Default
alpha boolean Perform an alphanumerical sort instead of a numeric one false
by string Instead 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
direction string Sort in ascendant (ASC) or descendant (DESC) order ASC
get array Sort 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 values null
limit array Limit the result set to a range of matching elements (similar to SELECT LIMIT offset, count in SQL).
Format: [<offset(int)>, <count(int)>]
queuable boolean Make this request queuable or not true

Callback Response #

Returns an array of sorted values.

Usage #

Copied to clipboard!
use \Kuzzle\Kuzzle;
$kuzzle = new Kuzzle('localhost');
try {
  $values = $kuzzle->memoryStorage()->sort('key');
catch (ErrorException $e) {

Callback response:

Copied to clipboard!
["sorted element1", "sorted element2", "..."]