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.
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.
Related Products
on GumroadDevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
Redis Command Tester
Test Redis commands in your browser with no install needed. Simulate SET, GET, HSET, LPUSH, EXPIRE, TTL and more with color-coded output and a built-in command reference.
Open free tool →
Redis Pipeline Builder
Build Redis command pipelines visually. Add GET, SET, HSET, LPUSH, EXPIRE and other commands, reorder them, and export as raw pipeline, redis-cli, or Node.js ioredis code.
Open free tool →
Redis Connection String Builder
Build Redis connection strings and URLs from host, port, password, database, and TLS settings. Generate code examples for redis-py, ioredis, and Lettuce.
Open free tool →
More Free Tools
Related Articles
Redis Caching Patterns for Node.js: Cache-Aside, Write-Through, and TTL Strategies
Master Redis caching patterns in Node.js: cache-aside, write-through, write-behind, read-through, and TTL strategies. Code examples, when to use each pattern, and cache invalidation techniques.
Redis in 2026: Caching, Pub/Sub, Streams, and Vector Search
Modern Redis patterns for Node.js developers. Covers ioredis vs node-redis, cache-aside and write-through patterns, pub/sub with Upstash, Redis Streams for event sourcing, and Redis Stack vector search for AI apps.
Caching Strategies for Web Developers: Browser, CDN, Server-Side, and Database
Complete guide to web caching strategies. Covers HTTP cache headers, CDN configuration, Redis/Memcached patterns, service workers, and database query caching with practical code examples and performance benchmarks.
Redis vs Memcached vs Valkey: Caching Comparison 2026
Complete comparison of Redis, Memcached, and Valkey for caching in 2026. Covers data structures, persistence, clustering, memory management, use cases, performance benchmarks, and managed service pricing.
Redis vs Memcached vs Dragonfly vs KeyDB: Caching Solutions 2025
In-depth comparison of Redis, Memcached, Dragonfly, and KeyDB for 2025. Benchmarks, use cases, and a decision guide to pick the right caching layer for your stack.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →