ZADD
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn’t exist.
Browse all commands · Upstream source documentation
| Reference field | Value |
|---|---|
| Canonical name | ZADD |
| Catalog group | Sorted set commands |
| Upstream since | 1.2.0 — upstream Redis/module version, not an ffkv release |
| Pinned catalog | Redis 8.10.0 |
Syntax
Section titled “Syntax”ZADD key [NX | XX] [GT | LT] [CH] [INCR] score member [score member ...]ffkv behavior and limits
Section titled “ffkv behavior and limits”Scores and lexicographic ranges are separate query modes. Do not rely on random-pop order; sorted-set storage remains RAM-resident in hybrid mode.
Source: README.md:275–295, 810–825; tests/bdd/features/sorted_sets.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.
Upstream metadata
Section titled “Upstream metadata”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(log(N)) for each item added, where N is the number of elements in the sorted set.
Upstream arity: -4 (includes the command name; a negative number is a minimum).
Command flags: WRITE, DENYOOM, FAST.
ACL categories: SORTEDSET.
Argument structure
Section titled “Argument structure”| Argument | Type | Constraints / metadata |
|---|---|---|
key | key | key_spec_index: 0 |
condition | oneof | optional; since: 3.0.2 |
↳ nx | pure-token | token: NX |
↳ xx | pure-token | token: XX |
comparison | oneof | optional; since: 6.2.0 |
↳ gt | pure-token | token: GT |
↳ lt | pure-token | token: LT |
change | pure-token | optional; token: CH; since: 3.0.2 |
increment | pure-token | optional; token: INCR; since: 3.0.2 |
data | block | multiple |
↳ score | double | Required |
↳ member | string | Required |
Key specifications
Section titled “Key specifications”Upstream key discovery descriptors (indexes are relative to the full command vector):
[ { "flags": [ "RW", "UPDATE" ], "begin_search": { "index": { "pos": 1 } }, "find_keys": { "range": { "lastkey": 0, "step": 1, "limit": 0 } } }]Additional pinned upstream metadata
{ "group": "sorted_set", "since": "1.2.0", "history": [ [ "2.4.0", "Accepts multiple elements." ], [ "3.0.2", "Added the `XX`, `NX`, `CH` and `INCR` options." ], [ "6.2.0", "Added the `GT` and `LT` options." ] ]}Metadata source · Local snapshot: src/command_metadata.json, key zadd.
BDD coverage and source examples
Section titled “BDD coverage and source examples”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.
- Type distinguishes built in values and missing keys without inspecting their contents —
tests/bdd/features/generic.feature:1352; invocation observed. - ZADD applies conditional changes sequentially and preserves expiry —
tests/bdd/features/sorted_sets.feature:4; command tag and invocation observed. - Cardinality counts distinct members rather than score pairs —
tests/bdd/features/sorted_sets.feature:44; invocation observed. - Score ranges honor strict boundaries and infinities —
tests/bdd/features/sorted_sets.feature:68; invocation observed. - Increment returns its resolved score and rejects NaN without mutation —
tests/bdd/features/sorted_sets.feature:92; invocation observed. - Individual scores preserve absent members —
tests/bdd/features/sorted_sets.feature:121; invocation observed. - Multiple score lookup preserves input order and missing slots —
tests/bdd/features/sorted_sets.feature:145; invocation observed. - Ranks use lexicographic tie breaks and optional score —
tests/bdd/features/sorted_sets.feature:161; invocation observed. - Reverse ranks invert member order within tied scores —
tests/bdd/features/sorted_sets.feature:185; invocation observed. - Modern ranges support score and lex modes with reverse pagination —
tests/bdd/features/sorted_sets.feature:209; invocation observed. - Legacy score range returns scores with negative unlimited count —
tests/bdd/features/sorted_sets.feature:241; invocation observed. - Legacy reverse score range reverses bounds and tie order —
tests/bdd/features/sorted_sets.feature:257; invocation observed. - Reverse rank range counts indexes from the reverse ordering —
tests/bdd/features/sorted_sets.feature:273; invocation observed. - Lexical ranges distinguish inclusive and exclusive prefix bounds —
tests/bdd/features/sorted_sets.feature:289; invocation observed. - Reverse lex range supports offset and unbounded endpoints —
tests/bdd/features/sorted_sets.feature:313; invocation observed. - Lex cardinality counts only the selected binary interval —
tests/bdd/features/sorted_sets.feature:337; invocation observed. - Explicit remove counts each member once and removes an empty key —
tests/bdd/features/sorted_sets.feature:361; invocation observed. - Rank removal resolves negative indexes before changing the indexes —
tests/bdd/features/sorted_sets.feature:385; invocation observed. - Score removal leaves exclusive lower-bound members intact —
tests/bdd/features/sorted_sets.feature:409; invocation observed. - Lex removal preserves scores and deletes the last-member key —
tests/bdd/features/sorted_sets.feature:433; invocation observed. - Minimum pop orders ties and accepts zero without consuming data —
tests/bdd/features/sorted_sets.feature:473; invocation observed. - Maximum pop reverses tied members and deletes the empty key —
tests/bdd/features/sorted_sets.feature:505; invocation observed. - Random members distinguish scalar and repeated scored arrays —
tests/bdd/features/sorted_sets.feature:529; invocation observed. - Scan returns real members and decimal score text —
tests/bdd/features/sorted_sets.feature:569; invocation observed. - Difference retains first-source scores and repeated sources cancel —
tests/bdd/features/sorted_sets.feature:585; invocation observed. - Difference store can overwrite its source and clears destination TTL —
tests/bdd/features/sorted_sets.feature:609; invocation observed. - Union applies per-input weights before aggregation including regular sets —
tests/bdd/features/sorted_sets.feature:641; invocation observed. - Intersection weights and MIN aggregate preserve shared members only —
tests/bdd/features/sorted_sets.feature:657; invocation observed. - Intersection cardinality supports regular sets duplicate keys and LIMIT —
tests/bdd/features/sorted_sets.feature:681; invocation observed. - Union store counts weighted memberships instead of original scores —
tests/bdd/features/sorted_sets.feature:705; invocation observed. - Intersection store resolves source aliasing and normalizes infinity NaN —
tests/bdd/features/sorted_sets.feature:729; invocation observed. - Range store resolves source before overwrite and preserves original scores —
tests/bdd/features/sorted_sets.feature:753; invocation observed. - Multi pop selects first nonempty source and returns nested pairs —
tests/bdd/features/sorted_sets.feature:801; invocation observed. - Blocking minimum pop wakes on insertion and returns a flat scored tuple —
tests/bdd/features/sorted_sets.feature:833; invocation observed. - Blocking maximum pop wakes and respects reverse tied member order —
tests/bdd/features/sorted_sets.feature:861; invocation observed. - Blocking multi pop wakes and caps count at available cardinality —
tests/bdd/features/sorted_sets.feature:889; invocation observed. - RESP3 scored ranges and pop replies use nested native doubles —
tests/bdd/features/sorted_sets.feature:917; invocation observed. - RESP3 algebra uses scored pairs and weighted COUNT ignores scores —
tests/bdd/features/sorted_sets.feature:950; invocation observed. - Invalid store options and source types do not destroy destination —
tests/bdd/features/sorted_sets.feature:975; invocation observed. - Malformed range bounds and limits leave data unchanged —
tests/bdd/features/sorted_sets.feature:1035; invocation observed. - Multi pop validates count and timeout before taking a member —
tests/bdd/features/sorted_sets.feature:1066; invocation observed. - Weight zero normalizes infinity products to zero and MIN differs from SUM —
tests/bdd/features/sorted_sets.feature:1102; invocation observed. - Resolved scores stores and removals survive crash recovery —
tests/bdd/features/sorted_sets.feature:1126; command tag and invocation observed. - RESP3 multi-pop keeps nested pairs and blocking pop keeps its flat tuple —
tests/bdd/features/sorted_sets.feature:1203; invocation observed. - Lex bounds compare binary bytes and store the selected scored members —
tests/bdd/features/sorted_sets.feature:1236; invocation observed. - Only union and intersection accept regular set inputs —
tests/bdd/features/sorted_sets.feature:1276; invocation observed. - Intersection preserves raw later infinity products in every aggregate and stored score (Scenario Outline) —
tests/bdd/features/sorted_sets.feature:1318; invocation observed. - An initial zero-weight infinity product is normalized but union normalizes all contributions —
tests/bdd/features/sorted_sets.feature:1357; invocation observed.
Extracted command vectors
Section titled “Extracted command vectors”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.
Blocking minimum pop wakes on insertion and returns a flat scored tuple — tests/bdd/features/sorted_sets.feature:839 (I execute:)
[ "ZADD", "second", "3", "member"]Next source assertion: the reply equals:
1Blocking maximum pop wakes and respects reverse tied member order — tests/bdd/features/sorted_sets.feature:867 (I execute:)
[ "ZADD", "ranked", "5", "a", "5", "z"]Next source assertion: the reply equals:
2Blocking multi pop wakes and caps count at available cardinality — tests/bdd/features/sorted_sets.feature:895 (I execute:)
[ "ZADD", "second", "1", "a", "2", "b"]Next source assertion: the reply equals:
2