redis-expert
它能做什么
这个技能指导将 Redis 用作快速数据存储,用于缓存、排行榜、事件流和消息传递。适合希望快速读写又不拖慢系统的开发者。
适用场景
- ✓当你需要在较慢的数据库或 API 前面加一层缓存时。
- ✓当你想基于 Redis 构建排行榜、计数器或事件流时。
- ✓当 Redis 中的数据必须在重启后保留,并且你需要选择持久化设置时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/redis-expert/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我们的商品页面添加 Redis 缓存,使重复访问不必每次都查询数据库,并让缓存值在十分钟后过期。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐为每项工作选择合适的数据结构,为每个缓存键设置过期时间,并在生产环境中使用安全、非阻塞的命令。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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/EXECor client-side pipelining to reduce round-trip latency from N calls to 1 - Write Lua scripts with
EVALfor 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, andZREVRANKfor leaderboards, rate limiters, and priority queues - Store structured objects as hashes with
HSET/HGETALLrather than serialized JSON strings to enable partial updates - Use
OBJECT ENCODINGandMEMORY USAGEcommands 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
ZRANGEBYSCOREto count requests in a sliding window;ZREMRANGEBYSCOREto 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; useSCANwith 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-limitand design scripts to be fast
常见问题
为什么每个缓存键都应该过期?
没有过期时间的键会不断堆积,直到内存耗尽,然后 Redis 可能删除你真正想保留的键。
Redis 是永久存储吗?
该技能默认把 Redis 视为临时存储,只有在数据必须在重启后保留时,才建议使用仅追加文件持久化。
生产环境中应避免什么?
该技能说明应避免对大型集合执行慢命令,并用 SCAN 代替 KEYS。
详情
作者的原始描述
Redis expert for data structures, caching patterns, Lua scripting, and cluster operations
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10705
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。