Keys disappearing on Upstash Redis: TTL, eviction, or a writer you forgot
Keys vanish because of TTL expiry, eviction, or a writer deleting them. Check TTL first, then memory pressure, then your write paths. Not the full reference manual.
TL;DR: Keys vanish because of TTL expiry, eviction, or a writer deleting them. Check TTL first, then memory pressure, then your write paths. Fix and verify Set explicit TTLs where expiry is intended, raise the data-size limit or add eviction-safe namespacing where it is not, and prefix keys per service (serviceA:..., serviceB:...). Re-run the TTL check after the fix: hot keys should show -1 or the intended expiry.
The fix
Diagnosing disappearing keys on Upstash Redis
Symptom
GET returns null for keys you know were written. Intermittent, or mass disappearances at once.
Step 1: check TTL
Run TTL on a missing key right after a fresh write. If it returns a positive number counting down, something set an expiry: your SET included EX, or a framework session default did. If TTL returns -1, the key has no expiry and the cause is elsewhere. If -2, the key is already gone.
Common trap: session libraries and cache helpers set short default TTLs. Your code wrote the key correctly and the library expired it an hour later.
Step 2: check memory pressure
If the database is near its data-size limit (256MB on free, configured size on fixed plans), eviction removes keys to make room. The console shows memory usage. A database pinned near 100% with keys vanishing is eviction, not a bug.
Step 3: check writers
DEL or UNLINK in a code path you forgot: cleanup jobs, deploy scripts, key-prefix migrations.
- FLUSHDB/FLUSHALL anywhere in scripts or runbooks. Grep for them.
Key collisions: two services sharing a database and a key prefix. One services invalidation deletes the others keys.
Fix and verify
Set explicit TTLs where expiry is intended, raise the data-size limit or add eviction-safe namespacing where it is not, and prefix keys per service (serviceA:..., serviceB:...). Re-run the TTL check after the fix: hot keys should show -1 or the intended expiry.
When to use this
- This covers exactly what the title says: Keys disappearing on Upstash Redis.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Keys; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Compatibility
- Not pinned to a specific version; follows current Keys behavior.