The Complete Redis CLI Commands Cheat Sheet: Strings, Hashes, Lists & TTL
Quick reference for key expiration, high-performance data structures, pub/sub messaging, and memory inspection.
Table of Contents
Key Expiration & String Operations
Standard caching primitives with automatic time-to-live expiration.
| Command | Description | Time Complexity |
|---|---|---|
| `SET key "value" EX 3600` | Stores string value with an automatic 1-hour expiration timestamp. | O(1) |
| `GET key` | Retrieves the value associated with key (or nil if expired/missing). | O(1) |
| `TTL key` | Returns remaining time-to-live in seconds (-1: immortal, -2: expired). | O(1) |
| `SCAN 0 MATCH "user:*" COUNT 100` | Iterates keys safely using cursors without blocking the Redis event loop. | O(1) per scan batch |
Hashes, Lists & Queues
Structured data storage and atomic FIFO queues.
| Command | Data Type | Description |
|---|---|---|
| `HSET user:100 name "Alice" role "Admin"` | Hash | Sets multiple field-value pairs in a single Redis hash structure. |
| `HGETALL user:100` | Hash | Retrieves all fields and values stored in hash key. |
| `LPUSH queue:jobs "task_42"` | List | Pushes a new item to the head of a FIFO task queue. |
| `RPOP queue:jobs` | List | Atomically pops and returns the oldest item from the tail of the queue. |
Memory Inspection & Pub/Sub
Debugging performance bottlenecks and real-time message broadcasting.
# Subscribe to a channel
SUBSCRIBE notifications:app
# Publish message to channel (in separate client)
PUBLISH notifications:app "Deployment completed"
# Inspect memory footprint of a large key
MEMORY USAGE user:session:9812
# Check total server health and memory saturation
INFO memoryInteractive Client-Side Tools for this Guide
Test and run these patterns directly inside your browser with zero server uploads:
JSON Formatter & Validator (Beautify & Minify)
Clean up messy API responses, fix syntax glitches, and compress JSON payloads directly in your browser.
Base64 Encoder & Decoder (Text & Images)
Convert binary images and strings into Base64 format for web embeds, CSS inlining, and data transmission.
Unix Timestamp Converter (Epoch to Human Date)
Convert seconds and milliseconds epoch timestamps to human-readable datetime formats across all timezones.
Frequently Asked Questions
Why should you never run KEYS * on a production Redis instance?
Redis is single-threaded. Running `KEYS *` against millions of keys blocks all other incoming database operations, causing application-wide timeouts. Always use `SCAN`.
What happens when Redis exceeds its allocated maxmemory limit?
Depending on the `maxmemory-policy` (e.g. volatile-lru, allkeys-lru, or noeviction), Redis will either purge expired/idle keys or return error responses for write commands.