From cc-use-exp
Enforces Redis safety and performance rules: bans KEYS/FLUSHALL, requires SCAN, TTL, pipeline batching, and big-key limits. Works with go-redis, Jedis, redis-py, ioredis.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cc-use-exp:redis-safetyThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> 防止 Redis 常见性能和稳定性问题,适用于所有语言。
防止 Redis 常见性能和稳定性问题,适用于所有语言。
| 禁止 | 替代 | 原因 |
|---|---|---|
KEYS * / KEYS pattern | SCAN 游标迭代 | KEYS 是 O(N) 阻塞操作,生产环境会导致 Redis 卡死 |
FLUSHDB / FLUSHALL | 按 key 前缀 SCAN + DEL | 全量删除风险极高 |
| 无 TTL 的 SET | 所有 key 必须设置 TTL | 避免内存泄漏 |
// Go (go-redis) ❌
keys, _ := rdb.Keys(ctx, "user:*").Result()
// Go (go-redis) ✅
var cursor uint64
for {
keys, cursor, _ = rdb.Scan(ctx, cursor, "user:*", 100).Result()
// 处理 keys
if cursor == 0 { break }
}
// Java (Jedis) ❌
Set<String> keys = jedis.keys("user:*");
// Java (Jedis) ✅
ScanParams params = new ScanParams().match("user:*").count(100);
String cursor = "0";
do {
ScanResult<String> result = jedis.scan(cursor, params);
// 处理 result.getResult()
cursor = result.getCursor();
} while (!cursor.equals("0"));
# Python (redis-py) ❌
keys = r.keys("user:*")
# Python (redis-py) ✅
for key in r.scan_iter(match="user:*", count=100):
# 处理 key
多次 Redis 调用应使用 Pipeline 减少网络往返:
// ❌ 循环单次调用
for _, id := range ids {
rdb.Get(ctx, "user:"+id)
}
// ✅ Pipeline 批量
pipe := rdb.Pipeline()
for _, id := range ids {
pipe.Get(ctx, "user:"+id)
}
pipe.Exec(ctx)
// ❌
rdb.Set(ctx, "token:123", value, 0)
// ✅
rdb.Set(ctx, "token:123", value, 24*time.Hour)
npx claudepluginhub doccker/cc-use-exp --plugin cc-use-expRedis patterns for caching, rate limiting, distributed locks, session storage, Pub/Sub, and connection management in production applications.
Guides Redis system design: data structures for caching, queues, leaderboards, sessions; caching strategies, pub/sub, streams, clustering, memory optimization, Lua scripting.
Redis data structure patterns, caching strategies, distributed locks, rate limiting, pub/sub, and connection management for production applications.