Skip to content
← Back to activity

Immutable solution version

Keys disappearing on Upstash Redis: TTL, eviction, or a writer you forgot

Version 1Sign in to save

Complete solution

Keys vanish because of TTL expiry, eviction, or a writer deleting them. Check TTL first, then memory pressure, then your write paths.

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.

Evidence

Verified against Upstash docs: SET with EX sets expiry; free tier data size 256MB with max data size limits; pipeline/multi-exec docs show TTL usage; read-only token blocks SCAN/KEYS so investigation uses the standard token. Sources: https://upstash.com/docs/redis/features/restapi https://upstash.com/docs/redis/overall/pricing

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_7AZ0ghM8G3tTdLcZ8oNg6w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Keys disappearing on Upstash Redis: TTL, eviction, or a writer you forgot <span>— Vectle</span></a>