Redis Command Cheatsheet
Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. This cheatsheet summarizes the most commonly used Redis commands, grouped by data type and function for quick reference.
Updated: 2026-07-17·35 commands
Overview
Redis (Remote Dictionary Server) is an in-memory data structure store used as a database, cache, and message broker. This cheatsheet covers the most commonly used Redis commands organized by data type.
Quick Start
``bash
redis-cli ping # Test connection
redis-cli # Enter interactive mode
``
Refer to the command table below for detailed usage.
Basic Ops(11)
| Command | Level | ||
|---|---|---|---|
SET key value [NX|XX] [EX seconds] [PX milliseconds]Set the value of a key, with optional NX (only if not exists), XX (only if exists), EX (seconds), PX (milliseconds) | Basic | SET user:1001 "alice" EX 3600 NX | |
GET keyGet the value of a key | Basic | GET user:1001 | |
DEL key [key ...]Delete one or more keys | Basic | DEL user:1001 session:abc | |
EXISTS key [key ...]Check if one or more keys exist, returns the count of existing keys | Basic | EXISTS user:1001 session:abc | |
TYPE keyReturn the type of the value stored at a key | Basic | TYPE user:1001 | |
EXPIRE key secondsSet a key time to live in seconds | Basic | EXPIRE cache:page 300 | |
TTL keyGet the remaining time to live of a key in seconds. -1 means no expiry, -2 means key does not exist | Basic | TTL cache:page | |
RENAME key newkeyRename a key, overwrites the destination if it already exists | Intermediate | RENAME user:1001 user:1001-backup | |
KEYS patternFind all keys matching the given pattern. WARNING: blocks Redis on large datasets in production | Expert | KEYS user:* | |
INFO [section]Get information and statistics about the Redis server, optionally filtered by section (server, memory, stats) | Intermediate | INFO memory | |
FLUSHALL [ASYNC]Delete all keys from all databases. Extremely dangerous in production; always back up first. Supports ASYNC mode | Expert | FLUSHALL ASYNC |
Strings(4)
| Command | Level | ||
|---|---|---|---|
MSET key value [key value ...]Set multiple key-value pairs atomically | Intermediate | MSET user:1001 alice user:1002 bob | |
MGET key [key ...]Get the values of multiple keys atomically | Intermediate | MGET user:1001 user:1002 | |
INCR keyIncrement the integer value of a key by one (atomic) | Basic | INCR counter:visits | |
DECR keyDecrement the integer value of a key by one (atomic) | Basic | DECR counter:stock |
Lists(6)
| Command | Level | ||
|---|---|---|---|
LPUSH key value [value ...]Prepend one or more values to a list (left side) | Basic | LPUSH logs:app error-timeout | |
RPUSH key value [value ...]Append one or more values to a list (right side) | Basic | RPUSH queue:tasks task123 | |
LPOP keyRemove and return the first element of a list (left side) | Basic | LPOP queue:tasks | |
RPOP keyRemove and return the last element of a list (right side) | Basic | RPOP queue:tasks | |
LLEN keyGet the length of a list | Basic | LLEN queue:tasks | |
LRANGE key start stopGet a range of elements from a list, inclusive of start and stop. Use negative numbers to count from the end | Basic | LRANGE queue:tasks 0 -1 |
Sets(4)
| Command | Level | ||
|---|---|---|---|
SADD key member [member ...]Add one or more members to a set | Basic | SADD roles:admin user:1001 user:1002 | |
SMEMBERS keyReturn all members of a set | Basic | SMEMBERS roles:admin | |
SINTER key [key ...]Return the intersection of multiple sets | Intermediate | SINTER roles:admin roles:editor | |
SUNION key [key ...]Return the union of multiple sets | Intermediate | SUNION roles:admin roles:editor |
Hashes(4)
| Command | Level | ||
|---|---|---|---|
HSET key field value [field value ...]Set the value of a field in a hash. Overwrites if the field already exists | Basic | HSET user:1001 name alice age 30 | |
HGET key fieldGet the value of a field in a hash | Basic | HGET user:1001 name | |
HGETALL keyGet all fields and values in a hash | Basic | HGETALL user:1001 | |
HDEL key field [field ...]Delete one or more fields from a hash | Basic | HDEL user:1001 age |
Sorted Sets(4)
| Command | Level | ||
|---|---|---|---|
ZADD key score member [score member ...]Add one or more members to a sorted set, or update the score of existing members | Intermediate | ZADD leaderboard 100 alice 95 bob | |
ZRANGE key start stop [WITHSCORES]Return members of a sorted set by index range (ascending order by score) | Intermediate | ZRANGE leaderboard 0 9 WITHSCORES | |
ZREVRANGE key start stop [WITHSCORES]Return members of a sorted set by index range (descending order by score) | Intermediate | ZREVRANGE leaderboard 0 9 WITHSCORES | |
ZRANK key memberDetermine the index of a member in a sorted set (ascending order, 0-based) | Intermediate | ZRANK leaderboard alice |
Pub/Sub(2)
| Command | Level | ||
|---|---|---|---|
PUBLISH channel messagePost a message to a channel | Intermediate | PUBLISH news:updates maintenance-2am | |
SUBSCRIBE channel [channel ...]Subscribe to one or more channels to receive messages. Note: the client enters listening mode after subscribing | Intermediate | SUBSCRIBE news:updates alerts |
FAQ
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.