Nâng CaoRedis iconRedis

Redis trong production: các best practices quan trọng nhất cần tuân thủ?

Vận hành Redis production tốt đòi hỏi cấu hình security đúng (auth, TLS, ACL), chọn persistence phù hợp, tránh blocking operation, và monitor các metric quan trọng như evicted_keys và slowlog.

Best practices khi vận hành Redis trong production:

  • Security: bật authentication (requirepass), dùng ACL (ACL SETUSER ... nocommands +@write) thay vì rename-command cho Redis 6.0+ để kiểm soát permission chi tiết hơn, bind Redis chỉ trên internal interface (không expose ra internet), dùng TLS cho Redis 6+.
  • Availability: dùng Sentinel hoặc Cluster, đặt replica-priority hợp lý, test failover định kỳ.
  • Performance: đặt maxmemory phù hợp với RAM (để lại 20-30% cho OS và fragmentation), chọn maxmemory-policy đúng, monitor slowlog (slowlog-log-slower-than 10000 microseconds).
  • Tránh blocking operation: không dùng KEYS * trên production (dùng SCAN), không dùng SMEMBERS trên Set lớn (dùng SSCAN), cẩn thận với SORT, LRANGE trên List dài.
  • Connection management: dùng connection pool (max pool size = 10-50), set tcp-keepalive 300.
  • Backup: cấu hình RDB snapshot, monitor rdb_last_save_timerdb_changes_since_last_save.
  • Upgrade: Redis minor version backward compatible, major version cần test kỹ; dùng Redis managed service (ElastiCache, Redis Cloud) để giảm operational burden.

Xem toàn bộ Redis cùng filter theo level & chủ đề con.

Mở danh sách Redis