Interactive engineering lab

Set member expiration: NX, XX, GT and LT on a timeline

Replay SADD, SADDEX, SEXPIRE, STTL and SPERSIST on a logical clock and read each documented reply.

By Sandeep Belgavi · Published 2026-11-26 · Prepared 2026-11-25

Synthetic fixtures computed locally. No model or production service is contacted.

Experiment workspace

Decision trace

    The question this experiment answers

    What does each Redis 8.12 set-member expiration command reply, and what state does it leave behind? The lab replays a list of commands against one set key on a logical clock in seconds. It implements the rules printed on the redis.io pages for SEXPIRE, STTL, SPERSIST and SADDEX, read on 2026-11-25, and reproduces every example on those pages. It is not a Redis server, and it was not run against one.

    Change one assumption at a time

    Choose a scenario preset to load a command script, then edit the script freely and run it. Supported lines are SADD key member..., SADDEX key [MNX or MXX] [EX seconds or KEEPTTL] MEMBERS count member..., SEXPIRE key seconds [NX, XX, GT or LT] MEMBERS count member..., STTL key MEMBERS count member..., SPERSIST key MEMBERS count member..., SREM key member..., SISMEMBER key member, SCARD key and ADVANCE seconds. Lines starting with # are comments. A malformed line is reported as an error and leaves the set unchanged, as a rejected command would.

    Expected outcomes

    The documented preset returns -2 and -2 for SEXPIRE on a missing key, then 1, 1 and -2, then 0 for NX on a member that already has a TTL, then 1 for GT with a longer TTL, and STTL returns 20 and 10. The SADD preset shows STTL 900 after a plain SADD and -1 after a plain SADDEX. The GT preset returns 0 for GT on a persistent member and 1 for LT; after ADVANCE 61 the member is missing while SCARD still reports 1. The zero preset returns 2 for each removal and leaves the key absent. The lag preset shows SISMEMBER 0 for an expired member while SCARD reports 2 and the live count is 1.

    Read the table and the trace

    Each row shows the clock, the command, its reply, the live member count, the stored member count that SCARD may report, and every stored member with its expiry time. The trace explains each reply in terms of the documented rule. Start trace, Next step, Show all and the slider reveal a prefix of the same steps without recomputing.

    Reset and export

    Reset inputs restores the first preset and reruns it. Export JSON downloads the script, every row, the metrics, the trace, the model version and the limitations. Editing the script disables export until the next run so a stale result is never exported against new commands. Nothing is stored or sent.

    Limits

    Only second-resolution commands are modelled; SPEXPIRE, PX, EXAT, PXAT and the millisecond and timestamp readers are omitted. Reclamation of expired members is modelled as lazy, which is why SCARD is shown as an upper bound. Replication, persistence, keyspace notifications and memory are not modelled. Confirm behaviour against a Redis 8.12 server before relying on it. Views are my own and do not represent any employer, past or present.