Skip to content
Search ffkv docs

Search the complete handbook, locally.

    SORT

    Sorts the elements in a list, a set, or a sorted set, optionally storing the result.

    Browse all commands · Upstream source documentation

    Reference fieldValue
    Canonical nameSORT
    Catalog groupGeneric commands
    Upstream since1.0.0 — upstream Redis/module version, not an ffkv release
    Pinned catalogRedis 8.10.0
    SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern
    ...]] [ASC | DESC] [ALPHA] [STORE destination]

    TTL deadlines use wall-clock time and remain absolute across restart. Key/database operations can overwrite or remove data; SCAN is incremental rather than an atomic snapshot. New typed structures remain in RAM in hybrid mode.

    Source: README.md:193–195, 375–377, 584–585; tests/bdd/features/generic.feature.

    All requests share the 8 MiB framing/1,024-argument ingress limit; normal RESP replies have 64 MiB wire/logical budgets with bounded nesting/value counts. Management and Lua origins impose smaller budgets. These are not a process RSS cap. Catalog inclusion is not exhaustive option or wire-format parity. See limits and compatibility.

    The following fields come from the pinned Redis metadata, not measured ffkv performance or an assertion that ffkv enforces every upstream flag. Running COMMAND INFO/COMMAND DOCS describe the current engine.

    Upstream Redis complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).

    Upstream arity: -2 (includes the command name; a negative number is a minimum).

    Command flags: WRITE, DENYOOM.

    ACL categories: SET, SORTEDSET, LIST, DANGEROUS.

    ArgumentTypeConstraints / metadata
    keykeykey_spec_index: 0
    by-patternpatternoptional; token: BY; key_spec_index: 1
    limitblockoptional; token: LIMIT
    ↳ offsetintegerRequired
    ↳ countintegerRequired
    get-patternpatternoptional; multiple; multiple token; token: GET; key_spec_index: 1
    orderoneofoptional
    ↳ ascpure-tokentoken: ASC
    ↳ descpure-tokentoken: DESC
    sortingpure-tokenoptional; token: ALPHA
    destinationkeyoptional; token: STORE; key_spec_index: 2

    Upstream key discovery descriptors (indexes are relative to the full command vector):

    [
    {
    "flags": [
    "RO",
    "ACCESS"
    ],
    "begin_search": {
    "index": {
    "pos": 1
    }
    },
    "find_keys": {
    "range": {
    "lastkey": 0,
    "step": 1,
    "limit": 0
    }
    }
    },
    {
    "notes": "For the optional BY/GET keyword. It is marked 'unknown' because the key names derive from the content of the key we sort",
    "flags": [
    "RO",
    "ACCESS"
    ],
    "begin_search": {
    "unknown": null
    },
    "find_keys": {
    "unknown": null
    }
    },
    {
    "notes": "For the optional STORE keyword. It is marked 'unknown' because the keyword can appear anywhere in the argument array",
    "flags": [
    "OW",
    "UPDATE"
    ],
    "begin_search": {
    "unknown": null
    },
    "find_keys": {
    "unknown": null
    }
    }
    ]
    Additional pinned upstream metadata
    {
    "group": "generic",
    "since": "1.0.0"
    }

    Metadata source · Local snapshot: src/command_metadata.json, key sort.

    These are source observations, not a test run performed by this documentation build. A tag identifies scenario intent; an extracted vector identifies a command invocation, which may intentionally produce an error. Scenarios may require setup, multiple connections, persistence, cluster nodes or native-module fixtures.

    • A denied actual SORT lookup logs the resource and leaves STORE unchanged — tests/bdd/features/client_control_repair.feature:621; command tag and invocation observed.
    • Sort resolves external hash weights and multiple GET patterns before limiting and storing — tests/bdd/features/generic.feature:1203; command tag and invocation observed.
    • A failed numeric sort cannot alter its store destination or the original collection — tests/bdd/features/generic.feature:1267; command tag and invocation observed.

    The following JSON arrays are the test harness’s argument vectors, not shell commands. Numeric arguments are converted by the harness; objects of the form {"base64":"…"} represent decoded binary bytes, not a literal JSON command argument. Preserve scenario setup and connection ordering. See the CLI guide for shell quoting and binary stdin. No reply is invented or inferred.

    Sort resolves external hash weights and multiple GET patterns before limiting and storing — tests/bdd/features/generic.feature:1249 (I execute:)

    [
    "SORT",
    "ids",
    "ALPHA",
    "DESC",
    "LIMIT",
    0,
    2
    ]

    Next source assertion: the reply equals:

    ["c","b"]

    A failed numeric sort cannot alter its store destination or the original collection — tests/bdd/features/generic.feature:1273 (I execute:)

    [
    "SORT",
    "numbers",
    "STORE",
    "result"
    ]

    Next source assertion: the reply is an error with code “ERR”

    A denied actual SORT lookup logs the resource and leaves STORE unchanged — tests/bdd/features/client_control_repair.feature:632 (client “sort-user” executes:)

    [
    "SORT",
    "sort-source",
    "BY",
    "secret:*",
    "ALPHA",
    "STORE",
    "sort-destination"
    ]

    Next source assertion: the reply is an error with code “NOPERM”