Redis Cheatsheet - Redis Command Reference
For developers using Redis as a cache who must care about memory and TTL strategy. The commands are easy, but big keys blowing up memory, hot keys concentrating load on one node, and cache penetration/avalanche are the real business problems. By the end you can pick the right command per data structure, use INFO memory and object encoding to find top memory consumers, understand the RDB/AOF persistence trade-off, and use SCAN/UNLINK to handle big keys without blocking the instance.
Connection 6
redis-cli -h 127.0.0.1 -p 6379 -a passwordredis-cli --scan --pattern "user:*"redis-cli -r 5 -i 1 INFO memoryAUTH passwordSELECT 0DBSIZEData Structure 11
SET key value EX 300GET keyMSET k1 v1 k2 v2HSET user:1 name "tom" age 30HGETALL user:1LPUSH queue task1BRPOP queue 30ZADD rank 100 "user1" 200 "user2"ZRANGE rank 0 -1 WITHSCORESSADD tags "python" "redis"SINTER set1 set2Key Space 8
EXPIRE key 300TTL keyTYPE keyDEL key1 key2UNLINK keyRENAME old_key new_keyRANDOMKEYOBJECT ENCODING keyPersistence & Memory 7
BGSAVELASTSAVEBGREWRITEAOFINFO memoryMEMORY USAGE keyCONFIG GET maxmemoryCONFIG GET maxmemory-policySlowlog & Monitor 6
SLOWLOG GET 10SLOWLOG RESETCONFIG GET slowlog-log-slower-thanCLIENT LISTCLIENT KILL ID <id>INFO clientsCluster & Replication 5
CLUSTER INFOCLUSTER NODESCLUSTER KEYSLOT keyINFO replicationROLETips
- Never use KEYS * in production — use SCAN instead. KEYS blocks the main thread and causes stuttering.
- Use UNLINK instead of DEL for large keys (lists/hashes/sets) — DEL blocks the main thread.
- mem_fragmentation_ratio > 1.5 indicates high fragmentation — consider restarting or enabling activedefrag.
FAQ
What is the difference between Redis and Memcached, and when should I use Redis?
Redis supports multiple data structures (strings, hashes, lists, sets, sorted sets) with built-in persistence, while Memcached is simple key-value and pure memory. Choose Redis when you need complex data operations, persistence, leaderboards, message queues, or session storage.
Why should I avoid the KEYS * command in production?
KEYS * traverses the entire keyspace and blocks the Redis main thread; with large datasets it causes stalls and timeouts. Use SCAN instead, which iterates keys incrementally without blocking.
Can Redis lose data? How do I ensure persistence?
Redis offers RDB (point-in-time snapshots) and AOF (append-only log) persistence. RDB restores fast but may lose data after the last snapshot; AOF is safer but larger. Production usually enables both to balance performance and safety.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us