method

RedisClient.sort

key: KeyLike,
...args: string | number[]
): Promise<number | null | string[]>;

Sort the elements in a list, set or sorted set

@param key

The key to sort

@param args

Optional BY, LIMIT, GET, ASC/DESC, ALPHA, STORE modifiers

@returns

Promise that resolves with the sorted elements (null for a GET pattern whose key is missing), or the count if STORE is used

await redis.rpush("mylist", "3", "1", "2");
await redis.sort("mylist"); // ["1", "2", "3"]
await redis.sort("mylist", "DESC"); // ["3", "2", "1"]
await redis.sort("mylist", "GET", "missing:*"); // [null, null, null]

Referenced types

type KeyLike = string | ArrayBufferView | Blob