Database & In-Memory CacheUpdated: 2026-11-07

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.

Redis is the world’s most popular in-memory key-value data store, used for high-speed caching, session management, real-time analytics, and message brokering. Reference these essential CLI commands for daily operations.

Key Expiration & String Operations

Standard caching primitives with automatic time-to-live expiration.

CommandDescriptionTime 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.

CommandData TypeDescription
`HSET user:100 name "Alice" role "Admin"`HashSets multiple field-value pairs in a single Redis hash structure.
`HGETALL user:100`HashRetrieves all fields and values stored in hash key.
`LPUSH queue:jobs "task_42"`ListPushes a new item to the head of a FIFO task queue.
`RPOP queue:jobs`ListAtomically pops and returns the oldest item from the tail of the queue.

Memory Inspection & Pub/Sub

Debugging performance bottlenecks and real-time message broadcasting.

Pub/Sub Messaging & Memory Profilingbash
# 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 memory

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.