Skip to main content

Redis TTL Calculator

Calculate cache expiration times and generate Redis commands. Includes TTL jitter, cache strategy patterns, and command reference.

TTL Duration Builder

Quick Presets

Cache Strategy Presets

Results

Total seconds
With jitter range
Human readable

Redis Commands

EXPIRE — Set TTL on existing key
PEXPIRE — Set TTL in milliseconds
EXPIREAT — Expire at Unix timestamp
SET EX — Set value with TTL atomically

Jitter Code (Python)

 

Frequently Asked Questions

What is Redis TTL?▼

TTL (Time To Live) is the expiration time for a Redis key. After the TTL expires, Redis automatically deletes the key. Set it with EXPIRE key seconds or EXPIREAT key unix-timestamp. Check remaining TTL with TTL key (returns -1 if no expiry, -2 if key doesn't exist).

What Redis commands set expiry?▼

EXPIRE key seconds — set TTL in seconds. PEXPIRE key milliseconds — set TTL in milliseconds. EXPIREAT key timestamp — expire at Unix timestamp. PEXPIREAT key milliseconds-timestamp — expire at ms timestamp. SET key value EX seconds — set value with TTL atomically. In Redis 7.0+, EXPIRE supports NX/XX/GT/LT options.

What is the best TTL for caching?▼

It depends on data volatility and acceptable staleness: Real-time data (stock prices, live scores): 1-5 seconds. Session tokens: 15-30 minutes. User profile cache: 5-15 minutes. Product catalog: 1-6 hours. Static reference data (countries, categories): 24 hours. Computed aggregates (daily stats): until next compute cycle.

How do I avoid cache stampede with TTL?▼

Cache stampede happens when many keys expire simultaneously, causing all requests to hit the database at once. Solutions: 1) Jitter — add random offset to TTL (base + rand(0, jitter)). 2) Probabilistic early expiration — start refreshing before expiry. 3) Background refresh — never let cache miss hit the DB directly. 4) Lock with SETNX — only one process refreshes, others wait.

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 →