Đến nội dung hướng dẫn
Mục lục tài liệu · Thêm cache với Redis

Xây dựng & kết nối

Thêm cache với Redis

Kết hợp app deploy với Redis cho cache, session, rate limit, queue nhẹ và pub/sub.

Trong trang này

Bạn sẽ build gì

Một app dùng Redis để cache dữ liệu đọc nhiều, lưu session, chống spam bằng rate limit, chạy queue nhẹ hoặc pub/sub. App vẫn deploy bằng Flash Deploy; Redis xử lý dữ liệu tốc độ cao.

Sơ đồ minh họa

Luồng thao tác chính (không phải ảnh Console)

Cache ready

Cache

GET/SET/session

Limits

Commands/bandwidth

Commands

Biết command bị chặn

Redis usage

1Commands 38%
2Bandwidth 22%
3Storage 14%
4Connections healthy

Luồng trên Console

  1. Tạo Redis database trong Console.
  2. Lấy private Host/Port cùng Username/Password trong Connection cho app cùng org; dùng public endpoint cho client bên ngoài.
  3. Thêm `REDIS_HOST`, `REDIS_PORT`, `REDIS_USERNAME`, `REDIS_PASSWORD` vào env của project app.
  4. Redeploy app để runtime nhận credential mới.
  5. Kiểm tra Redis metrics: Commands, Bandwidth, Storage và Connections.
  6. Mở Command reference nếu thư viện Redis báo lỗi command bị chặn.

Vận hành sau deploy

  • Cache key nên có TTL để tránh storage tăng mãi.
  • Session/rate limit nên dùng prefix rõ ràng để dễ debug.
  • Nếu commands/sec tăng đột biến, kiểm tra retry loop hoặc endpoint đang gọi Redis quá nhiều.