Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Enforces Redis safety rules in go-redis, Jedis, redis-py, ioredis code: bans KEYS and FLUSHALL, requires SCAN, TTLs and batched pipelines.
Use this skill ↓77% 86%+9 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 17 of 22 without it.
When invoking SET commands across any Redis client library, what requirement must always be met regarding key lifetime?
Requires explicit TTL or expiration on all keys
3 of 3 safety checks passed
防止 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);
Published skills whose descriptions closely match this one, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.