Koskamo

Key expiration and TTLs

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Set a timeout on a key and it is automatically deleted after the timeout expires; a key with an associated timeout is said to be volatile. The timeout is cleared only by commands that delete or overwrite the key's contents — DEL, SET, GETSET, and all the *STORE commands — while operations that alter the value without replacing it, such as INCR, LPUSH, or HSET, leave it untouched. PERSIST clears a timeout. Redis expires keys passively when a client accesses a timed-out key, and actively by testing a random sample of keys with an expiration. On expiration the master synthesizes a DEL operation to the AOF file and replicas, which never expire keys independently. EXPIRE key seconds accepts NX, XX, GT, and LT modifiers: NX sets an expiry only when none exists, XX only when one does, and GT or LT only when the new expiry is greater or less than the current one, treating a non-volatile key as infinite. EXPIRE returns 1 when the timeout is set, 0 otherwise; SET on an existing key clears its expiry, resetting TTL to -1. Scope: Redis. Reviewed October 4, 2026.

Source and provenance

Original source
redis.io
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.