redis-cli command reference by data type, persistence and scaling concepts, and a correct-caching workflow.
| Category | Command | Description |
|---|---|---|
| Strings | SET key value | Sets a string key to a value, creating or overwriting it. |
| Strings | GET key | Reads the value of a string key. |
| Strings | SET key value EX 60 | Sets a key with a 60-second expiry — the core primitive behind Redis-based caching. |
| Expiry | EXPIRE key 60 | Sets a TTL on an existing key. |
| Expiry | TTL key | Returns seconds remaining until expiry, or -1 if no TTL is set. |
| Lists | LPUSH mylist value | Pushes a value onto the left end of a list — common for building a queue. |
| Lists | RPOP mylist | Pops a value from the right end — LPUSH+RPOP together implement a FIFO queue. |
| Hashes | HSET user:1 name "Alex" age 30 | Sets multiple fields on a hash — good fit for a small object like a user record. |
| Hashes | HGETALL user:1 | Returns every field/value pair in a hash. |
| Sets | SADD tags:post1 "redis" "cache" | Adds members to a set — duplicates are silently ignored. |
| Sorted Sets | ZADD leaderboard 100 "player1" | Adds a member with a score — sorted sets are how Redis implements leaderboards/rankings. |
| Pub/Sub | PUBLISH channel "message" | Publishes a message to a channel — subscribers connected via SUBSCRIBE receive it immediately. |
| Introspection | KEYS pattern* | Finds keys matching a pattern — blocks the server on a large dataset; use SCAN in production instead. |
| Server | INFO | Dumps server stats — memory usage, connected clients, keyspace hits/misses. |
Core Data Types
String
Binary-safe text or a number — the simplest type, also used for counters via INCR/DECR.
List
An ordered collection of strings, efficient at both ends — the basis for simple queues.
Hash
A map of field-value pairs under one key — a compact way to store an object without a separate key per field.
Set
An unordered collection of unique strings — fast membership checks and set operations (union, intersect).
Sorted Set
A set where every member has a score, kept in score order — powers leaderboards and range queries by score.
Stream
An append-only log of entries with IDs — used for event/message processing, similar in spirit to a lightweight Kafka topic.
Persistence & Scaling
RDB Snapshots
AOF
Replication
Cluster Mode
Always set a TTL
A cache key with no expiry is a slow memory leak — SET with EX (or SETEX) so stale data ages out even if invalidation logic is imperfect.
Namespace keys with colons
user:1:profile, session:abc123 — keeps related keys groupable and makes SCAN patterns meaningful.
Handle cache misses gracefully in the app
Redis being down or a key missing should degrade to hitting the source of truth, not error out — a cache is an optimization, not a dependency.
Watch eviction policy under memory pressure
maxmemory-policy (e.g. allkeys-lru) determines what gets dropped when Redis hits its memory limit — the default (noeviction) just starts rejecting writes instead.