Common Redis Commands Cheat Sheet
18. Common Redis Commands Cheat Sheet
Section titled “18. Common Redis Commands Cheat Sheet”Command Types Overview
Section titled “Command Types Overview”flowchart TB CMDS[Redis Commands] --> Strings["🔤 Strings<br/>SET / GET / INCR / MSET<br/>Values, counters, tokens"] CMDS --> Lists["📋 Lists<br/>LPUSH / RPUSH / LPOP / LRANGE<br/>Queues, timelines"] CMDS --> Sets["🔢 Sets<br/>SADD / SINTER / SUNION / SDIFF<br/>Unique members, tags"] CMDS --> SortedSets["🏆 Sorted Sets<br/>ZADD / ZRANGE / ZREVRANK<br/>Leaderboards, rankings"] CMDS --> Hashes["🗂️ Hashes<br/>HSET / HGET / HGETALL / HINCRBY<br/>Objects, profiles"] CMDS --> Keys["🔑 Keys & TTL<br/>EXPIRE / TTL / SCAN / TYPE<br/>Management"] CMDS --> Server["⚙️ Server<br/>INFO / PING / CONFIG / MONITOR<br/>Administration"]
style CMDS fill:#7c3aed,color:#fff style Strings fill:#3b82f6,color:#fff style Lists fill:#059669,color:#fff style Sets fill:#f59e0b,color:#fff style SortedSets fill:#ec4899,color:#fff style Hashes fill:#06b6d4,color:#fff style Keys fill:#8b5cf6,color:#fff style Server fill:#10b981,color:#fffQuick reference: 7 command categories covering all essential Redis operations. Each section below has the full syntax.
String Commands
Section titled “String Commands”| Command | Syntax | Description |
|---|---|---|
SET | SET key value [EX seconds] | Set a key |
GET | GET key | Get a value |
MSET | MSET k1 v1 k2 v2 | Set multiple keys |
MGET | MGET k1 k2 | Get multiple values |
DEL | DEL key | Delete a key |
EXISTS | EXISTS key | Check if key exists (1/0) |
APPEND | APPEND key value | Append to string |
INCR | INCR key | Increment by 1 |
INCRBY | INCRBY key amount | Increment by N |
DECR | DECR key | Decrement by 1 |
List Commands
Section titled “List Commands”| Command | Syntax | Description |
|---|---|---|
LPUSH | LPUSH key val [val ...] | Push to left |
RPUSH | RPUSH key val [val ...] | Push to right |
LPOP | LPOP key | Pop from left |
RPOP | RPOP key | Pop from right |
LRANGE | LRANGE key 0 -1 | Get all elements |
LLEN | LLEN key | Get list length |
LINDEX | LINDEX key index | Get element at index |
LTRIM | LTRIM key start stop | Keep only a range |
BLPOP | BLPOP key timeout | Blocking pop from left |
Set Commands
Section titled “Set Commands”| Command | Syntax | Description |
|---|---|---|
SADD | SADD key member [...] | Add members |
SREM | SREM key member | Remove a member |
SMEMBERS | SMEMBERS key | Get all members |
SISMEMBER | SISMEMBER key member | Check membership |
SCARD | SCARD key | Count members |
SINTER | SINTER key1 key2 | Intersection |
SUNION | SUNION key1 key2 | Union |
SDIFF | SDIFF key1 key2 | Difference |
Sorted Set Commands
Section titled “Sorted Set Commands”| Command | Syntax | Description |
|---|---|---|
ZADD | ZADD key score member | Add with score |
ZRANGE | ZRANGE key 0 -1 WITHSCORES | Get ascending |
ZREVRANGE | ZREVRANGE key 0 -1 | Get descending |
ZRANK | ZRANK key member | Get rank (ascending) |
ZREVRANK | ZREVRANK key member | Get rank (descending) |
ZSCORE | ZSCORE key member | Get member’s score |
ZREM | ZREM key member | Remove a member |
ZCOUNT | ZCOUNT key min max | Count in score range |
Hash Commands
Section titled “Hash Commands”| Command | Syntax | Description |
|---|---|---|
HSET | HSET key field value | Set field |
HGET | HGET key field | Get field |
HGETALL | HGETALL key | Get all fields & values |
HMGET | HMGET key f1 f2 | Get multiple fields |
HDEL | HDEL key field | Delete a field |
HEXISTS | HEXISTS key field | Check if field exists |
HKEYS | HKEYS key | Get all field names |
HVALS | HVALS key | Get all values |
HINCRBY | HINCRBY key field N | Increment field by N |
Key & TTL Commands
Section titled “Key & TTL Commands”| Command | Syntax | Description |
|---|---|---|
EXPIRE | EXPIRE key seconds | Set TTL in seconds |
TTL | TTL key | Get remaining TTL |
PTTL | PTTL key | Get TTL in milliseconds |
PERSIST | PERSIST key | Remove TTL |
KEYS | KEYS pattern | Find matching keys (⚠️ avoid in prod) |
SCAN | SCAN cursor MATCH pattern COUNT N | Safely iterate keys |
TYPE | TYPE key | Get data type of key |
RENAME | RENAME key newkey | Rename a key |
RANDOMKEY | RANDOMKEY | Get a random key |
Server Commands
Section titled “Server Commands”| Command | Syntax | Description |
|---|---|---|
PING | PING | Test connection |
INFO | INFO | Server statistics |
DBSIZE | DBSIZE | Number of keys |
FLUSHDB | FLUSHDB | Delete all keys in current DB |
FLUSHALL | FLUSHALL | Delete all keys in all DBs |
SAVE | SAVE | Synchronous snapshot |
BGSAVE | BGSAVE | Asynchronous snapshot |
CONFIG GET | CONFIG GET maxmemory | Get config value |
CONFIG SET | CONFIG SET maxmemory 256mb | Set config value |
MONITOR | MONITOR | Real-time command log |