Skip to main content

Redis Command Reference

Browse and search 60+ Redis commands across all data structures — Strings, Hashes, Lists, Sets, Sorted Sets, Pub-Sub, Scripting, HyperLogLog, and Server commands. Each entry includes syntax, a real-world example, return type, and time complexity.

✓ 60+ commands, 10 categories ✓ Syntax + live examples ✓ Time complexity for every command ✓ Redis 7.x reference

Frequently Asked Questions

What is the difference between SET with EX and SETEX?▼

Both do the same thing — set a key with an expiration in seconds — but SET with EX is the preferred modern form (Redis 2.6.12+). SETEX is an older command that predates the option flags. Use SET key value EX 60 in new code. SETEX will not be removed, but the SET options are more flexible since you can also combine NX (only set if not exists) with EX in a single atomic command: SET lock:resource 1 EX 30 NX.

When should I use HSET vs individual string keys like user:42:name?▼

Use HSET when you have an object with many fields (users, sessions, config). It's more memory-efficient because Redis uses a compact ziplist encoding for small hashes (fewer than 128 fields under 64 bytes each). Individual string keys like user:42:name are fine for a few fields but multiply key overhead quickly at scale. As a rule: if you'd GROUP these in a struct in your code, use a hash in Redis.

Why is KEYS dangerous in production?▼

KEYS pattern is a blocking O(N) operation that scans the entire keyspace. On a large database with millions of keys, this can block Redis for seconds, freezing all other clients. Use SCAN key cursor [MATCH pattern] [COUNT count] instead — it iterates in non-blocking increments. The tradeoff is that SCAN may return duplicate keys and doesn't guarantee snapshot consistency, but it won't cause latency spikes.

What is the best data structure for a rate limiter in Redis?▼

For simple fixed-window rate limiting, use INCR + EXPIRE: INCR requests:user:42, then EXPIRE it to your window duration on the first hit. For a sliding window, use a Sorted Set: ZADD with the current timestamp as score, then ZREMRANGEBYSCORE to remove old entries and ZCARD to count current requests. The sorted set approach is more accurate but uses more memory. For very high throughput, a Lua script with EVAL ensures atomicity.

How does SETNX relate to distributed locking?▼

SETNX (set if not exists) is the foundation of distributed locks in Redis. The canonical pattern is: SET lock:resource unique-id EX 30 NX — this atomically acquires the lock only if it's free, with a built-in expiration to prevent deadlocks. When done, check that the value still matches your unique ID before deleting (use a Lua EVAL for atomic check-and-delete). The Redlock algorithm extends this to multiple Redis nodes for stronger guarantees.

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 →