Redis 教程

Redis 是什么、为什么快、以及这套教程怎么学。

Beginner
Key PointsRedis 是内存中的键值数据库:把数据放内存,读写都是微秒级,常用来做缓存、排行榜、消息队列。

Redis 是什么

Redis (REmote DIctionary Server) is an in-memory key-value database. Data lives mainly in RAM, so reads/writes are microsecond-fast, while async disk persistence keeps it safe.

能做什么

  • 缓存 —— 把热点数据放 Redis,挡在数据库前面,降低 DB 压力
  • 排行榜 —— 用 Sorted Set 做实时积分榜
  • 计数器 / 限流 —— INCR 原子自增
  • 消息队列 —— List / Stream 做轻量队列
  • 会话存储 —— 分布式下共享登录态

与其它存储对比

维度Redis关系型数据库
存储介质内存为主磁盘为主
读写速度微秒级毫秒级
数据结构丰富(5+ 种)表/行/列
典型角色缓存 / 加速主存储

学习路线

  1. 装好 redis-server 并连上 redis-cli
  2. 吃透 5 种基础结构:String / Hash / List / Set / Sorted Set
  3. 掌握键管理与过期(EXPIRE)
  4. 进阶:事务、持久化、管道、集群
Redis is a cache, not the source of truth — losing data (before persistence) is acceptable; the real store stays in MySQL/PG. Using Redis as the only store is a common architectural mistake.

Friends & Partners