Redis Commands & Key-Value Store Cheatsheet 2026
Reference guide for Redis strings, hashes, lists, sets, sorted sets, key expiration rules, pub/sub messaging, and server admin commands.
Keys & Expiration
When to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
EXISTS keyOutput Example
OKWhen to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
EXPIRE key 60Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
TTL keyOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
KEYS *Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
DEL keyOutput Example
OKStrings
When to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
SET key valueOutput Example
OKWhen to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
GET keyOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
INCR keyOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
DECR keyOutput Example
OKHashes
When to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
HSET user:1 name "Alex" age 30Output Example
OKWhen to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
HGET user:1 nameOutput Example
OKWhen to Use
When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.
Common Mistakes
Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.
Shortcut / Pro-Tip
Use TTL command to inspect how many seconds are left before a cached key expires.Example
HGETALL user:1Output Example
OKLists
When to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
LPUSH mylist "first"Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
RPUSH mylist "last"Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
LPOP mylistOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
LRANGE mylist 0 -1Output Example
OKSets & Sorted Sets
When to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
SADD myset "member"Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
SISMEMBER myset "member"Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
ZADD highscores 500 "player1"Output Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
ZRANGE highscores 0 -1 WITHSCORESOutput Example
OKServer Admin
When to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
PINGOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
FLUSHDBOutput Example
OKWhen to Use
When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.
Common Mistakes
Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.
Shortcut / Pro-Tip
Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.Example
MONITOROutput Example
OKRedis Best Practices
1Establish Clear Key Naming Patterns
Use colon-delimited names to structure key paths logically (e.g., object:id:attribute like 'user:1000:profile') for easy search and organization.
2Set TTLs on Caching Keys
Always specify expiration timers (TTL) on cache entries to prevent stale data accumulation and manage memory capacity automatically.
3Utilize Connection Pooling
Reuse connections through client pools rather than opening and closing TCP connections for every database query.
4Batch Queries with Pipelining
Group multiple commands into a single round-trip pipeline to minimize network latency overhead.
5Keep Memory Utilization under Control
Configure eviction policies (like volatile-lru or allkeys-lru) so the server handles out-of-memory states predictably.
Common Redis Errors & Solutions
OOM command not allowed when used memory > 'maxmemory'
Redis has filled up its allocated RAM and the active eviction policy cannot free any space. Solution: Increase MaxMemory settings, or optimize key expirations.
WRONGTYPE Operation against a key holding the wrong kind of value
Applying a command to an incompatible data structure (e.g. running HGET on a String key). Solution: Verify key type using the 'TYPE <key>' command first.
KEYS command timed out / locked database
Running 'KEYS *' on large production databases blocks the single-threaded CPU loop. Solution: Transition all search queries to use the non-blocking SCAN command.
NOAUTH Authentication required
The server has pass protection active but no password was sent. Solution: Run 'AUTH <password>' prior to executing data commands.
Connection refused
The redis-cli client is unable to establish a port link. Solution: Verify that the Redis daemon is running and bound to correct host IPs/ports.
Common Redis Interview Questions
Q1What is Redis and what is its primary use case?
Redis (Remote Dictionary Server) is an open-source, in-memory key-value data store used primarily as a database, cache, message broker, and queue, known for sub-millisecond response latencies.
Q2What are some data structures supported by Redis?
Redis supports Strings, Hashes, Lists, Sets, Sorted Sets (with range queries), Bitmaps, HyperLogLogs, Geospatial indexes, and Streams.
Q3How does Redis handle data persistence?
Redis offers two main persistence options: RDB (Redis Database) which takes point-in-time snapshots of your dataset at specified intervals, and AOF (Append Only File) which logs every write command received by the server.
Q4What is Redis Sentinel?
Redis Sentinel is a system designed to manage Redis instances. It handles high-availability monitoring, automatic failover of a master server to a replica, and client service discovery configuration.
Q5How does a Redis Hash differ from a standard String key-value?
A Redis Hash is an object structure containing field-value pairs, which is highly efficient for representing flat user profiles or models, saving memory overhead compared to single JSON string keys.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com