Skip to content

Redis

一句话解释

Redis 是 in-memory 键-值数据库 — 它存储数据 as 键-值 pairs in RAM for sub-millisecond access.

用大白话说

Redis (Remote Dictionary Server) is an in-memory key-value store. It keeps all data in RAM, which makes it extremely fast — sub-millisecond reads and writes. The trade-off is that data is volatile (lost on restart) unless you enable persistence.

Redis stores key-value pairs: SET name "Ada" stores the value "Ada" under the key "name", and GET name retrieves it. Beyond simple strings, Redis supports lists, sets, sorted sets, hashes, and more.

Common use cases:

  • Caching: store frequently accessed data to avoid hitting the main database.
  • Session storage: keep user sessions in Redis for fast access.
  • Rate limiting: count requests per user with atomic increments.
  • Real-time features: leaderboards, pub/sub messaging, queues.

Redis is not a replacement for your main database — it is a fast companion for specific use cases.

示例

bash
# Set and get a value
redis-cli SET user:1:name "Ada"
redis-cli GET user:1:name  # → "Ada"

# Increment a counter (atomic)
redis-cli INCR page:home:views
redis-cli INCR page:home:views
redis-cli GET page:home:views  # → "2"

Redis 存储键-值 pairs in memory. INCR atomically increments 计数器.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表