Sets #
21 commands: membership, the three set-algebra families, expiry, and deterministic SPOP.
| Cmd | RW | Syntax | Returns | Example → reply |
|---|---|---|---|---|
SADD | W | SADD KEY MEMBER [MEMBER ...] | integer members added | SADD tags go db → 2 |
SREM | W | SREM KEY MEMBER [MEMBER ...] | integer members removed | SREM tags db → 1 |
SCARD | R | SCARD KEY | integer cardinality | SCARD tags → 1 |
SISMEMBER | R | SISMEMBER KEY MEMBER | integer 0/1 | SISMEMBER tags go → 1 |
SMEMBERS | R | SMEMBERS KEY | array of members | SMEMBERS tags → [go] |
SDIFF | R | SDIFF KEY [KEY ...] | array members in the first but no later set | SDIFF a b → [x] |
SDIFFSTORE | W | SDIFFSTORE dest KEY [KEY ...] | integer size of the result | SDIFFSTORE out a b → 1 |
SINTER | R | SINTER KEY [KEY ...] | array members in every set | SINTER a b → [y] |
SINTERSTORE | W | SINTERSTORE dest KEY [KEY ...] | integer size of the result | SINTERSTORE out a b → 1 |
SUNION | R | SUNION KEY [KEY ...] | array members in any set | SUNION a b → [x,y] |
SUNIONSTORE | W | SUNIONSTORE dest KEY [KEY ...] | integer size of the result | SUNIONSTORE out a b → 2 |
SMOVE | W | SMOVE source destination MEMBER | integer 1 moved, 0 not a member | SMOVE a b x → 1 |
SPOP | W | SPOP KEY [count] | bare: bulk member; with count: array | SPOP queue:ready → job:7 |
SRANDMEMBER | R | SRANDMEMBER KEY [count] | bare: bulk; positive count: distinct array; negative: array with repeats | SRANDMEMBER tags 1 → [go] |
SKEYEXISTS | R | SKEYEXISTS KEY | integer 0/1 — does the set exist | SKEYEXISTS tags → 1 |
SCLEAR | W | SCLEAR KEY | integer members removed | SCLEAR tags → 1 |
SMCLEAR | W | SMCLEAR KEY [KEY ...] | integer sets removed | SMCLEAR a b → 2 |
SEXPIRE | W | SEXPIRE KEY seconds | integer 1/0 | SEXPIRE tags 60 → 1 |
SEXPIREAT | W | SEXPIREAT KEY unixTime | integer 1/0 | SEXPIREAT tags 1767225600 → 1 |
STTL | R | STTL KEY | integer seconds left, -1 none | STTL tags → 59 |
SPERSIST | W | SPERSIST KEY | integer 1 removed, 0 none | SPERSIST tags → 1 |
Notes #
SPOPis deterministic across replicas. Because it is a write command, its result must be identical on every node, so the picked member is derived from the Raft-seeded state rather thanmath/rand. Withcount, the count is clamped to the set size;count = 0answers an empty array and a negative count is an error.SRANDMEMBERis a read command and may use real randomness (countdistinct members when positive, repeats when negative).|count|is capped at 1048576.SMOVEto the same key is a no-op that returns1and keeps the TTL.SCLEAR/SMCLEARdelete whole sets and their expiration;SREMremoves members.SPERSISTis the only*PERSISTcommand in the engine, and it is known to leave the expiration in place on theipfsbackend. Strings, hashes and lists have noPERSISTat all.- Set algebra commands read the sets named in the arguments;
*STOREvariants overwrite the destination and return the size of the result.