跳转到内容

Redis 缓存

[cache]
cache_type = "Redis"
redis_url = "redis://localhost:6379"
max_size_mb = 100
  • 商品目录查询
  • 分类列表
  • 会话数据
  • 限流器状态

默认是内存缓存(cache_type = "Memory")。单节点部署这就够用了 —— Redis 是可选的,不是必需的。只有当你运行多个需要共享 缓存/会话/限流状态的 API 实例,或希望缓存能熬过重启时,才需要 Redis。

Terminal window
# 安装 Redis
sudo apt install redis-server
# 配置 Redis
sudo vim /etc/redis/redis.conf
# 设置: requirepass your_password
# 更新 rCommerce 配置
[cache]
cache_type = "Redis"
redis_url = "redis://:your_password@localhost:6379"

有了 Redis,多个 rCommerce 实例可以共享缓存和会话数据:

Instance 1 → Redis ← Instance 2

以下操作会自动失效缓存:

  • 商品创建/更新/删除
  • 分类变更
  • 下单
  • 配置变更