Skip to main content

Redis Key Namespace

v1.0.0

Key naming convention generator — env / app / type / id segments with TTL hints.

Redis Key Namespace Design
# Redis Key Namespace: myapp:prod:{entity}:{id}

| Pattern | Type | TTL |
|---|---|---|
| `myapp:prod:user:{userId}` | Hash — user profile | TTL: 7 days (sessions) or no TTL |
| `myapp:prod:session:{token}` | String — serialized session JSON | TTL: 1 hour |
| `myapp:prod:cart:{userId}` | Hash — cart items keyed by productId | TTL: 30 days |
| `myapp:prod:rl:{ip}:{endpoint}` | String — request count | TTL: 60 seconds (sliding window) |
| `myapp:prod:cache:{resource}:{hash}` | String — JSON serialized cache | TTL: 5 minutes (configurable) |

## Rules
- Always scan with `SCAN` not `KEYS *` in production
- Use `OBJECT ENCODING` to verify memory layout
- Set maxmemory-policy: allkeys-lru (cache) or noeviction (critical data)
- Monitor keyspace with `redis-cli --stat`