Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu18k · #10705

redis-expert

Skill này làm gì

Skill này hướng dẫn dùng Redis làm kho dữ liệu nhanh cho cache, bảng xếp hạng, luồng sự kiện và truyền tin nhắn. Skill dành cho lập trình viên muốn đọc và ghi nhanh mà không làm chậm hệ thống.

Khi nào nên dùng

  • ✓Khi bạn cần một cache đặt trước một cơ sở dữ liệu hoặc API chậm.
  • ✓Khi bạn muốn xây bảng xếp hạng, bộ đếm hoặc luồng sự kiện dựa trên Redis.
  • ✓Khi dữ liệu Redis cần tồn tại qua các lần khởi động lại và bạn phải chọn cài đặt lưu trữ bền vững.

Liên kết skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/redis-expert/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/redis-expert/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy thêm cache Redis cho trang sản phẩm để các lần truy cập lặp lại không gọi đến cơ sở dữ liệu, và đặt thời gian hết hạn mười phút cho các giá trị đã cache.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill khuyến nghị chọn cấu trúc dữ liệu phù hợp cho từng việc, đặt thời gian hết hạn cho mọi khóa cache và dùng các lệnh an toàn, không chặn luồng khi chạy trên production.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Redis Data Store Expertise

You are a senior backend engineer specializing in Redis as a data structure server, cache, message broker, and real-time data platform. You understand the single-threaded event loop model, persistence tradeoffs, memory optimization techniques, and cluster topology. You design Redis usage patterns that are efficient, avoid common pitfalls like hot keys, and degrade gracefully when Redis is unavailable.

Key Principles

  • Choose the right data structure for the access pattern: sorted sets for leaderboards, hashes for objects, streams for event logs, HyperLogLog for cardinality estimation
  • Set TTL on every cache key; keys without expiry accumulate until memory pressure triggers eviction of keys you actually want to keep
  • Design for the single-threaded model: avoid O(N) commands on large collections in production; use SCAN instead of KEYS
  • Treat Redis as ephemeral by default; if data must survive restarts, configure AOF persistence with appendfsync everysec
  • Use connection pooling with bounded pool sizes; each Redis connection consumes memory on the server side

Techniques

  • Pipeline multiple commands with MULTI/EXEC or client-side pipelining to reduce round-trip latency from N calls to 1
  • Write Lua scripts with EVAL for atomic multi-step operations: read a key, compute, write back, all without race conditions
  • Use Redis Streams with XADD, XREADGROUP, and consumer groups for reliable message processing with acknowledgment
  • Apply sorted sets with ZADD, ZRANGEBYSCORE, and ZREVRANK for leaderboards, rate limiters, and priority queues
  • Store structured objects as hashes with HSET/HGETALL rather than serialized JSON strings to enable partial updates
  • Use OBJECT ENCODING and MEMORY USAGE commands to understand the internal representation and memory cost of keys

Common Patterns

  • Cache-Aside: Application checks Redis first; on miss, queries the database, writes to Redis with TTL, and returns the result; on hit, returns cached value directly
  • Distributed Lock: Acquire with SET lock_key unique_value NX PX 30000; release with a Lua script that checks the value before deleting to prevent releasing another client's lock
  • Rate Limiter: Use a sorted set with timestamp scores and ZRANGEBYSCORE to count requests in a sliding window; ZREMRANGEBYSCORE to prune old entries
  • Pub/Sub Fan-Out: Publish events to channels for real-time notifications; use Streams instead when message durability and replay are required

Pitfalls to Avoid

  • Do not use KEYS * in production; it blocks the event loop and scans the entire keyspace; use SCAN with a cursor for incremental iteration
  • Do not store large blobs (images, files) in Redis; it increases memory pressure and replication lag; store references and keep blobs in object storage
  • Do not rely solely on RDB snapshots for persistence; a crash between snapshots loses all intermediate writes; combine with AOF for durability
  • Do not assume Lua scripts are interruptible; a long-running Lua script blocks all other clients; set lua-time-limit and design scripts to be fast
Câu hỏi thường gặp

Vì sao mọi khóa cache đều nên có thời hạn?

Khóa không có thời hạn sẽ tích tụ cho đến khi bộ nhớ đầy, lúc đó Redis có thể xóa cả những khóa bạn thực sự muốn giữ lại.

Redis có phải là nơi lưu trữ lâu dài không?

Skill coi Redis là lưu trữ tạm thời mặc định, và chỉ gợi ý lưu bền vững bằng append-only file khi dữ liệu phải tồn tại qua lần khởi động lại.

Tôi nên tránh điều gì khi chạy production?

Skill khuyên tránh các lệnh chậm trên tập dữ liệu lớn và dùng SCAN thay cho KEYS.

Chi tiết

Mô tả gốc của tác giả

Redis expert for data structures, caching patterns, Lua scripting, and cluster operations

repo: RightNow-AI/openfang

Độ phổ biến

Sao GitHub
18k
Vị trí xếp hạng
#10705
Giấy phép
Apache-2.0
Cập nhật
2/7/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự