用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Dev-Toolbelt/dev-team-agents --skill redis命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | redis |
| description | Redis — data structures, keyspace, persistence, clustering, pub/sub. |
Load when the project uses Redis (signal: redis, ioredis, redis-py, REDIS_URL, redis: in docker-compose, Laravel CACHE_DRIVER=redis).
redis-cli -h "${REDIS_HOST:-localhost}" -p "${REDIS_PORT:-6379}" -a "$REDIS_PASSWORD"
# with TLS (Redis 6+):
redis-cli -h "$REDIS_HOST" -p "${REDIS_PORT:-6380}" --tls -a "$REDIS_PASSWORD"
# using URL:
redis-cli -u "$REDIS_URL"
Key inspection commands:
redis-cli INFO server # version, uptime, mode
redis-cli INFO memory # used_memory, maxmemory, fragmentation
redis-cli INFO stats # ops/sec, hits, misses
redis-cli --latency # rolling latency histogram
redis-cli --bigkeys # scan for large keys (use on low-traffic periods)
redis-cli MONITOR # real-time command stream (dev only; high overhead)
| Type | Use when | Key commands |
|---|---|---|
| String | Counters, cached values, sessions, feature flags | GET, SET, INCR, SETNX, GETSET |
| Hash | Object fields; partial updates without serializing whole object | HGET, HSET, HMGET, HINCRBY |
| List | Queues (FIFO/LIFO), activity feeds, message buffers | LPUSH, RPOP, BRPOP, LRANGE, LLEN |
| Set | Unique membership, tags, social graph intersections | SADD, SMEMBERS, SINTER, SDIFF |
| Sorted Set | Leaderboards, rate-limit windows, priority queues | ZADD, ZRANGE, ZRANK, ZRANGEBYSCORE |
| Bitmap | Compact boolean arrays (e.g., daily active users by index) | SETBIT, GETBIT, BITCOUNT, BITOP |
| HyperLogLog | Cardinality estimation with ~0.81% error, fixed 12 KB | PFADD, PFCOUNT, PFMERGE |
| Stream | Persistent, ordered event log; consumer groups | XADD, XREAD, XGROUP CREATE, XACK |
user:{id}:profile, session:{token}, ratelimit:{ip}:{minute}: as separator (convention); avoid spaces and special charsTTL on every cached key — never let cache grow unboundedlyuser:* patterns are fine; avoid * scans in production — use SCAN with MATCH and COUNT| Mode | Guarantees | Use when |
|---|---|---|
| No persistence | None (data lost on restart) | Pure cache, ephemeral queues |
| RDB (snapshot) | Point-in-time snapshot at intervals | Low RPO tolerance; fast restarts |
| AOF (append-only file) | Logs every write; fsync policy controls durability | Higher durability; larger disk use |
| RDB + AOF | Best of both | Production with data that must survive restarts |
AOF fsync options: always (safest, slowest), everysec (default, 1 s data loss risk), no (OS decides).
Set maxmemory and maxmemory-policy in redis.conf or at runtime:
| Policy | Behaviour |
|---|---|
noeviction | Returns error when memory full (default) |
allkeys-lru | Evict least recently used from all keys |
volatile-lru | Evict LRU from keys with TTL only |
allkeys-lfu | Evict least frequently used (Redis 4+) |
volatile-ttl | Evict key with shortest TTL first |
For a pure cache: use allkeys-lru or allkeys-lfu.
| Mode | Topology | When |
|---|---|---|
| Standalone | Single node | Dev / low-traffic |
| Sentinel | 1 primary + N replicas + sentinel processes | HA without sharding |
| Cluster | 16384 hash slots across N primaries | Horizontal scale + HA |
{user:123}:profile and {user:123}:sessions land on the same slotWAIT command for synchronous replication confirmation| Feature | Pub/Sub | Streams |
|---|---|---|
| Message persistence | None (fire-and-forget) | Yes — messages stored in log |
| Consumer groups | No | Yes — each group reads independently |
| At-least-once delivery | No | Yes — XACK acknowledgement |
| Backpressure | No | Yes — MAXLEN trim |
Use Streams for durable event queues; use Pub/Sub for lightweight real-time notifications only.
| Gotcha | Fix |
|---|---|
KEYS * blocks the event loop | Use SCAN with MATCH and COUNT 100 |
Large HGETALL on a hash with thousands of fields | Use HSCAN or restructure |
| No TTL on session keys → memory leak | Set TTL on every write; use OBJECT IDLETIME to audit |
SETNX + EXPIRE is not atomic | Use SET key value NX EX seconds (single command) |
| Cluster: cross-slot multi-key operations fail | Use hash tags {...} to co-locate related keys |
| AOF rewrite pauses | Schedule BGREWRITEAOF during low-traffic windows |