Redis Tutorial Home
Redis is an open-source in-memory key-value store that can be used as a database, cache, and message broker. It supports multiple data structures, delivers extremely high performance, and is an essential component in modern web applications.
What is Redis?
Redis stands for REmote DIctionary Server, developed by Salvatore Sanfilippo in 2009. It stores data in memory, providing blazing-fast read and write speeds capable of handling over 100,000 operations per second.
Core Features of Redis
| Feature | Description |
|---|---|
| In-memory storage | Data is stored in memory for extremely fast read and write speeds |
| Persistence | Supports RDB snapshots and AOF logging |
| Rich data types | Supports strings, hashes, lists, sets, sorted sets, and more |
| Atomic operations | All operations are atomic, with transaction support |
| Pub/Sub | Built-in publish/subscribe messaging system |
| High performance | Single-instance QPS can exceed 100k, with master-replica replication and cluster support |
What Can Redis Do?
1. Caching System
This is the most common use case. Store database query results, API responses, page fragments, etc., in Redis to dramatically boost application performance.
User Request → Check Redis Cache → Hit → Return
↓ Miss
Query DB → Store in Redis → Return
2. Session Storage
Store user login state, shopping carts, temporary data, etc., in Redis to support session sharing across distributed environments.
3. Message Queue
Use Redis Lists and Pub/Sub to implement lightweight message queues.
4. Leaderboards
Leverage the sorting capabilities of Sorted Sets for gaming leaderboards, trending lists, and more.
5. Counters
Use the INCR command on strings for article views, likes, visit statistics, and more.
6. Social Features
Use Set intersection and union operations to implement mutual friends, people you may know, and other social features.
Redis vs Other Databases
Redis vs Memcached
| Aspect | Redis | Memcached |
|---|---|---|
| Data types | Rich (5 basic types) | Strings only |
| Persistence | Supported | Not supported |
| Clustering | Native support | Requires client-side sharding |
| Memory management | More flexible | Simpler |
| Performance | Extremely high | Extremely high |
Redis vs Relational Databases (MySQL)
| Aspect | Redis | MySQL |
|---|---|---|
| Storage | Memory | Disk |
| Data model | Key-value | Relational tables |
| Query capability | Simple | Powerful (SQL) |
| Transaction support | Simple transactions | Full ACID |
| Performance | Extremely high | High |
| Persistence | Optional | Default |
Redis vs MongoDB
| Aspect | Redis | MongoDB |
|---|---|---|
| Data model | Key-value | Document (JSON) |
| Query language | Command-based | SQL-like |
| Memory usage | All in-memory | Memory + disk |
| Use cases | Cache, sessions, queues | Document storage, content management |
Redis Use Cases
Used by Major Internet Companies
- Weibo: Stores user relationships, message queues, trending topics
- Taobao: Product caching, shopping carts, flash sale systems
- WeChat: Session messages, Moments likes
- GitHub: Caching, queues, counters
Typical Application Scenarios
| Scenario | Data Type Used | Description |
|---|---|---|
| Caching | String | Store cached data with expiration |
| Session storage | String | Store user session info |
| Shopping cart | Hash | Store product IDs and quantities |
| Message queue | List | LPUSH/RPOP for queuing |
| Leaderboard | Sorted Set | Auto-sorting, real-time updates |
| Social relationships | Set | Friend lists, intersection calculations |
| Counter | String | INCR atomic increment |
| Rate limiting | String + TTL | Track access counts |
Redis Version History
| Version | Release Date | Key Features |
|---|---|---|
| 1.0 | 2009 | Initial release |
| 2.0 | 2010 | Virtual memory, Pub/Sub |
| 2.6 | 2012 | Lua scripting, improved expiration precision |
| 2.8 | 2013 | Partial sync, config rewrite |
| 3.0 | 2015 | Official cluster support |
| 3.2 | 2016 | GEO, bitmap optimizations |
| 4.0 | 2017 | Module system, mixed persistence |
| 5.0 | 2018 | Streams data type |
| 6.0 | 2020 | ACL access control, multi-threaded I/O |
| 7.0 | 2022 | Functions, multi-part AOF |
Who Is This Tutorial For?
- Backend developers: Learn Redis to boost application performance
- DevOps engineers: Master Redis deployment and optimization
- Architects: Understand Redis in system architecture
- Students: Learn modern database technology
Prerequisites
- Basic knowledge of Linux commands
- Familiarity with at least one programming language (Python, Java, Node.js, etc.)
- Basic understanding of database concepts
Tutorial Contents
This tutorial is divided into 4 parts:
- Redis Basics: Installation, configuration, basic operations
- Data Types in Depth: Strings, hashes, lists, sets, sorted sets
- Advanced Features: Transactions, persistence, security, performance optimization
- Practical Applications: Using Redis with Python, Java, Node.js
❓ FAQ
📖 Summary
- Redis is an in-memory key-value database with high performance and rich data types
- Commonly used for caching, session storage, message queues, leaderboards, etc.
- Compared to Memcached, Redis supports more data types and persistence
- Compared to MySQL, Redis is faster but not suitable for complex queries
- Recommended version: Redis 6.0 or later
📝 Exercises
- Think: In your projects, which scenarios are suitable for Redis?
- Research: Look at websites or apps you use regularly — what might they be using Redis for?
- Compare: What are the pros and cons of Redis vs Memcached? How would you choose?
Next Lesson
In the next lesson, we will learn Redis Installation, covering installation on Linux, Windows, and Mac.



