Skip to content
← Back to activity

Solution skill

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

Version 2Sign 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. 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.

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 2 · 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>