Complete 2026 Guide to Redis Commands: Everything You Need to Know
This article offers a comprehensive 2026 overview of Redis commands, organized by function, with clear usage examples, return values, performance notes, and best‑practice recommendations such as avoiding KEYS in production and using SCAN, making it a practical reference for developers and architects.
Redis is a core component in large‑scale architectures. This guide provides a complete overview of Redis commands, grouped by functionality, with usage examples, expected results, performance considerations, and best‑practice advice.
1. Redis Command Classification Overview
Redis 常用命令
│
├── Key管理
│ ├── KEYS *
│ ├── EXISTS key
│ ├── DEL key
│ ├── EXPIRE key seconds
│ └── BGSAVE
├── String操作
│ ├── SET key value
│ ├── GET key
│ └── INCR key
├── Hash操作
│ ├── HSET key field value
│ ├── HGET key field
│ └── HGETALL key
├── List操作
│ ├── LPUSH key value
│ └── LRANGE key start stop
├── 性能排查
│ ├── INFO
│ ├── MONITOR
│ └── BGSAVE2. KEYS – Query All Matching Keys
Purpose: View existing keys in Redis. KEYS * Example to query user‑related keys: KEYS user:* Result example:
1) user:1001
2) user:1002
3) user:1003Note: KEYS is an O(N) operation; using it on large datasets can block Redis’s single thread. Recommended alternative: SCAN.
3. EXISTS – Check If a Key Exists
EXISTS user:1001Result: (integer) 1 if the key exists, 0 otherwise.
Typical use case: cache‑hit detection.
if (redis.exists(key)) {
return redis.get(key);
}4. DEL – Delete a Key
DEL user:1001Delete multiple keys: DEL key1 key2 key3 Result: (integer) indicating the number of keys removed.
5. EXPIRE – Set Key Expiration
EXPIRE user:1001 3600Result: 1 (expiration set). Use TTL to view remaining time: TTL user:1001 Result example: 3500 seconds.
6. SET – Set String Value
SET name mikeResult: OK.
Set with expiration (seconds):
SET token abc123 EX 3600 EXsets seconds, PX sets milliseconds.
7. GET – Get String Value
GET nameResult: "mike". Commonly used for cache reads.
8. INCR – Increment Counter
INCR page:viewFirst call returns 1, second 2, etc. Typical for page‑view or like counters.
9. HSET – Store Object in a Hash
HSET user:1001 name mike age 28Advantages over plain strings: saves memory and allows field‑level updates.
10. HGET – Retrieve Hash Field
HGET user:1001 nameResult: "mike".
Retrieve all fields: HGETALL user:1001 Result example:
name mike
age 2811. LPUSH – Push Message onto a List
LPUSH order_queue order1001Insert another message: LPUSH order_queue order1002 List now holds order1002 then order1001. Used for message queues, task queues, and asynchronous processing.
12. LRANGE – View List Contents
LRANGE order_queue 0 -1Result shows all items in order.
View first 10 items:
LRANGE order_queue 0 913. INFO – Inspect Redis Runtime Status
General information: INFO Memory details: INFO memory Client list: INFO clients Replication status: INFO replication These commands are essential for online troubleshooting and performance monitoring.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
