Skip to main content

Redis Cache Key Convention Generator

Build Redis cache key patterns with namespace and segment configuration. Get TTL recommendations, SETEX/GET command examples, and key pattern conventions for your caching strategy.

✓ Namespace + segment builder ✓ TTL by data type ✓ SETEX / GET / SCAN examples ✓ Colon / pipe / dot separators

Key Pattern Builder

Key Segments

Generated Key Pattern & Commands

Recommended TTL:
 
 
 
 

Frequently Asked Questions

What is a Redis cache key naming convention?▼

A cache key naming convention is a structured pattern for Redis keys that makes them self-documenting, easy to namespace, and query-friendly with SCAN. Common patterns: colon-separated ('user:123:profile'), pipe-separated ('user|123|profile'), or dot-separated ('user.123.profile'). Colon-separated is the most widely adopted convention.

What is a good TTL for different data types?▼

General guidelines: User sessions: 30 min–24 hours (depending on security needs). API responses: 60–300 seconds (balance freshness vs load). Auth tokens: match token expiry (15 min for access tokens, 7 days for refresh). Rate limit counters: 1 minute or sliding window. Search results: 5–30 minutes. Product catalog: 1–24 hours. Use shorter TTLs for frequently changing data.

How do I invalidate all keys for a namespace in Redis?▼

Use SCAN with a glob pattern: SCAN 0 MATCH user:* COUNT 100. Never use KEYS * in production as it blocks the server. For atomic bulk deletion, use a Lua script: redis.call('DEL', unpack(redis.call('KEYS', ARGV[1]))). Better yet, use key prefixes designed for SCAN and delete in batches.

What is the maximum Redis key length?▼

Redis supports keys up to 512 MB, but best practice is to keep keys under 1KB for memory efficiency. Very long keys increase memory usage and slow down comparisons. Use SHA hashes for keys derived from large inputs (like full URL paths): 'api:response:'+sha256(url).

What is the difference between EXPIRE, EXPIREAT, and SETEX?▼

EXPIRE key seconds — sets TTL in seconds from now. EXPIREAT key timestamp — sets expiry at a Unix timestamp. PEXPIRE key ms — sets TTL in milliseconds. SETEX key seconds value — atomically SET + EXPIRE in one command. SET key value EX seconds — modern equivalent with additional options (NX, XX, GET). Always prefer atomic SET...EX over separate SET+EXPIRE.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →