# 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.