Redis Cheat Sheet & Quick Reference
This is a redis quick reference cheat sheet that lists examples of redis commands
- Published on
- /0/0/10 mins read/195 views
On this page
- 1 server info amp management
- 2 database management db switching amp keys
- 3 key management
- 4 string commands
- 5 hash commands
- 6 list commands
- 7 set commands
- 8 sorted set zset commands
- 9 hyperloglog commands
- 10 pubsub commands
- 11 transactions amp pipelining
- 12 scripting lua
- 13 streams commands
- 14 geo commands
- 15 bitmaps commands
- 16 connection amp client commands
- 17 memory amp performance
1. Server Info & Management
Description: Core commands to inspect, manage, or control the Redis server instance. Used for debugging, server monitoring, runtime config changes, and shutdowns.
| Command | Type | Description / Use Case |
|---|---|---|
PING |
Server | Test if Redis server is running. Returns PONG. |
INFO |
Server | Get server info & statistics (memory, clients, persistence, CPU). |
MONITOR |
Server | Real-time command monitoring (debugging). |
CONFIG GET <parameter> |
Server | Get server config value. |
CONFIG SET <parameter> <value> |
Server | Change server config at runtime. |
SHUTDOWN |
Server | Stop the Redis server. |
FLUSHALL |
Server | Delete all keys in all databases (dangerous!). |
FLUSHDB |
Server | Delete all keys in current database. |
CLIENT LIST |
Server | List connected clients. |
CLIENT KILL <ip:port> |
Server | Kill client connections. |
2. Database Management (DB Switching & Keys)
Description: Commands to manage Redis logical databases, switch between them, inspect database stats, and move/scan keys.
Commands:
| Command | Purpose |
|---|---|
CONFIG GET databases |
Show total DB count |
SELECT <index> |
Switch DB |
KEYS * |
List all keys |
SCAN 0 MATCH pattern |
Safe key scan |
DBSIZE |
Count keys in DB |
MOVE key index |
Move key to another DB |
FLUSHDB |
Clear current DB |
FLUSHALL |
Clear all DBs |
INFO keyspace |
Show DB stats |
CLIENT INFO |
Show current DB through db=X |
3. Key Management
Description: Commands that manage keys, TTLs, types, existence, renaming, or expiration behavior.
| Command | Type | Use Case |
|---|---|---|
KEYS <pattern> |
Keys | Find keys matching pattern (slow for production). |
SCAN <cursor> [MATCH pattern] [COUNT n] |
Keys | Incremental iteration over keys (safer than KEYS). |
DEL <key> |
Keys | Delete a key. |
EXISTS <key> |
Keys | Check if key exists. |
TYPE <key> |
Keys | Check key data type. |
RENAME <old> <new> |
Keys | Rename a key. |
EXPIRE <key> <seconds> |
Keys | Set key TTL in seconds. |
TTL <key> |
Keys | Get remaining TTL. |
PERSIST <key> |
Keys | Remove TTL, make key persistent. |
4. String Commands
Description: Basic key-value operations; strings are Redis' most used type, supporting counters, tokens, JSON, serialized data, etc.
| Command | Type | Use Case |
|---|---|---|
SET key value |
String | Store a string. |
GET key |
String | Retrieve string. |
SETEX key seconds value |
String | Set string with expiration. |
MSET key1 value1 key2 value2 ... |
String | Set multiple strings at once. |
MGET key1 key2 ... |
String | Get multiple strings. |
INCR key |
String | Increment integer value by 1. |
DECR key |
String | Decrement integer value by 1. |
APPEND key value |
String | Append to existing string. |
STRLEN key |
String | Get string length. |
5. Hash Commands
Description: Hashes are like small JSON objects or maps—used for user profiles, configs, small structured objects.
| Command | Type | Use Case |
|---|---|---|
HSET key field value |
Hash | Set a field in hash. |
HGET key field |
Hash | Get field value. |
HMSET key field1 val1 field2 val2 ... |
Hash | Set multiple fields. |
HMGET key field1 field2 ... |
Hash | Get multiple fields. |
HDEL key field |
Hash | Delete field from hash. |
HEXISTS key field |
Hash | Check if field exists. |
HGETALL key |
Hash | Get all fields + values. |
HKEYS key |
Hash | Get all field names. |
HVALS key |
Hash | Get all field values. |
HLEN key |
Hash | Number of fields in hash. |
6. List Commands
Description: Lists allow queues, stacks, job pipelines, FIFO/LIFO, and streams of items.
| Command | Type | Use Case |
|---|---|---|
LPUSH key value |
List | Push element to the left (start). |
RPUSH key value |
List | Push element to the right (end). |
LPOP key |
List | Pop element from left. |
RPOP key |
List | Pop element from right. |
LRANGE key start stop |
List | Get range of elements. |
LLEN key |
List | Get list length. |
LREM key count value |
List | Remove elements by value. |
LTRIM key start stop |
List | Trim list to given range. |
7. Set Commands
Description: Unique, unordered collections. Great for unique items, tags, memberships, etc.
| Command | Type | Use Case |
|---|---|---|
SADD key member |
Set | Add member. |
SREM key member |
Set | Remove member. |
SISMEMBER key member |
Set | Check if member exists. |
SMEMBERS key |
Set | Get all members. |
SCARD key |
Set | Number of members. |
SPOP key [count] |
Set | Pop random member(s). |
SRANDMEMBER key [count] |
Set | Get random member(s) without removing. |
SUNION key1 key2 ... |
Set | Union of sets. |
SINTER key1 key2 ... |
Set | Intersection of sets. |
SDIFF key1 key2 ... |
Set | Difference of sets. |
8. Sorted Set (ZSet) Commands
Description: Ordered sets where each member has a score. Used for ranking, leaderboards, priorities, expirations.
| Command | Type | Use Case |
|---|---|---|
ZADD key score member |
Sorted Set | Add member with score. |
ZREM key member |
Sorted Set | Remove member. |
ZRANGE key start stop [WITHSCORES] |
Sorted Set | Get range by rank. |
ZREVRANGE key start stop [WITHSCORES] |
Sorted Set | Get range by rank descending. |
ZRANGEBYSCORE key min max [WITHSCORES] |
Sorted Set | Get range by score. |
ZREVRANGEBYSCORE key max min |
Sorted Set | Get range by score descending. |
ZSCORE key member |
Sorted Set | Get member score. |
ZCARD key |
Sorted Set | Count of members. |
ZCOUNT key min max |
Sorted Set | Count members in score range. |
ZINCRBY key increment member |
Sorted Set | Increment score of a member. |
9. HyperLogLog Commands
Description: Approximate unique counting with extremely small memory footprint. Great for analytics.
| Command | Type | Use Case |
|---|---|---|
PFADD key element [element ...] |
HyperLogLog | Add elements. |
PFCOUNT key [key ...] |
HyperLogLog | Count approximate unique elements. |
PFMERGE destkey sourcekey [sourcekey ...] |
HyperLogLog | Merge multiple HyperLogLogs. |
10. Pub/Sub Commands
Description: Messaging system built into Redis for subscribers and publishers.
| Command | Type | Use Case |
|---|---|---|
PUBLISH channel message |
Pub/Sub | Publish message to channel. |
SUBSCRIBE channel [channel ...] |
Pub/Sub | Subscribe to channel(s). |
PSUBSCRIBE pattern [pattern ...] |
Pub/Sub | Subscribe to pattern. |
UNSUBSCRIBE [channel ...] |
Pub/Sub | Unsubscribe from channels. |
PUNSUBSCRIBE [pattern ...] |
Pub/Sub | Unsubscribe from patterns. |
11. Transactions & Pipelining
Description: Execute commands atomically or send multiple commands without waiting for responses.
| Command | Type | Use Case |
|---|---|---|
MULTI |
Transaction | Start transaction block. |
EXEC |
Transaction | Execute queued commands. |
DISCARD |
Transaction | Discard transaction. |
WATCH key [key ...] |
Transaction | Watch keys for changes. |
UNWATCH |
Transaction | Unwatch all keys. |
12. Scripting (Lua)
Description: Run server-side scripts for atomic logic and batching.
| Command | Type | Use Case |
| EVAL script numkeys key [key ...] arg [arg ...] | Scripting | Execute Lua script. |
| EVALSHA sha1 numkeys key ... | Scripting | Execute cached Lua script by SHA1. |
13. Streams Commands
Description: Append-only log data structure for event processing, message queues, and real-time pipelines.
| Command | Type | Use Case |
|---|---|---|
XADD key ID field value [field value ...] |
Stream | Add entry to stream. |
XREAD COUNT n STREAMS key [key ...] ID [ID ...] |
Stream | Read entries. |
XDEL key ID [ID ...] |
Stream | Delete entry by ID. |
XLEN key |
Stream | Get stream length. |
XRANGE key start end [COUNT n] |
Stream | Get entries in range. |
XREVRANGE key end start [COUNT n] |
Stream | Get entries in reverse. |
14. Geo Commands
Description: Store geospatial coordinates, get distances, radius queries, etc.
| Command | Type | Use Case |
|---|---|---|
GEOADD key longitude latitude member |
Geo | Add geo location. |
GEOPOS key member [member ...] |
Geo | Get coordinates. |
GEODIST key member1 member2 [unit] |
Geo | Distance between members. |
GEORADIUS key lon lat radius unit [WITHCOORD] [WITHDIST] [WITHHASH] |
Geo | Query by radius. |
GEORADIUSBYMEMBER key member radius unit ... |
Geo | Query by member location. |
15. Bitmaps Commands
Description: Store user activity logs, tracking bits, analytics, boolean states efficiently.
| Command | Type | Use Case |
|---|---|---|
SETBIT key offset value |
Bitmap | Set bit at offset. |
GETBIT key offset |
Bitmap | Get bit at offset. |
BITCOUNT key [start end] |
Bitmap | Count bits set to 1. |
BITOP operation destkey key [key ...] |
Bitmap | Perform AND/OR/XOR/NOT on keys. |
16. Connection & Client Commands
| Command | Type | Use Case |
|---|---|---|
AUTH password |
Connection | Authenticate with password. |
SELECT index |
Connection | Switch database index (0-15 default). |
QUIT |
Connection | Close connection. |
17. Memory & Performance
Description: Useful for debugging performance issues, memory leaks, fragmentation, and optimization.
| Command | Type | Use Case |
|---|---|---|
MEMORY USAGE key |
Memory | Memory used by a key. |
MEMORY STATS |
Memory | Redis memory statistics. |
MEMORY PURGE |
Memory | Purge unused memory. |
LATENCY DOCTOR |
Performance | Suggest latency improvements. |
This cheat sheet covers almost everything Redis supports in CLI, including Strings, Hashes, Lists, Sets, Sorted Sets, Pub/Sub, Streams, Geo, Bitmaps, HyperLogLog, Transactions, Scripting, Memory & Server management.
Related Articles

- 206
- 0
- 0
