From ct
Provides deep operational guidance for Redis: persistence tradeoffs, eviction policies, latency diagnostics, cluster/Sentinel topology, replication, and fork variants. Use for troubleshooting Redis in production.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ct:redisThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Concise operational pointers for deep Redis troubleshooting and tuning.
Concise operational pointers for deep Redis troubleshooting and tuning.
Assumes you already know SET/GET/EXPIRE/TTL and basic data types. This skill covers the operational layer — the parts models tend to gloss over: persistence durability math, eviction internals, latency monitoring, cluster topology, replication, and the post-2024 fork landscape.
Load when the question is about:
MEMORY USAGE/DOCTOR/STATS, --bigkeys, fragmentation, activedefrag)SLOWLOG, LATENCY MONITOR, fork stalls, AOF rewrites)down-after-milliseconds, parallel-syncs, split-brain)PSYNC partial vs full, repl-backlog-size, min-replicas-to-write)MULTI/EXEC/WATCH (atomicity, optimistic locking, RTT batching)XCLAIM/XAUTOCLAIM, at-least-once delivery)--hotkeys, INFO commandstats, why not MONITOR)Do NOT load for: writing SET/GET/HSET, basic data-type questions, library client tutorials, schema-style key naming. Those don't need this skill.
dump.rdb). Smallest file, fastest restart. Default trigger save 3600 1 300 100 60 10000 (Redis 7+) — snapshot if 1 change in 1h or 100 in 5min or 10000 in 60s. BGSAVE for manual; SAVE blocks the main thread (don't use in prod).appendonly yes. Fsync policy via appendfsync:
always — fsync per write. Strong durability, ~1k ops/s ceiling on rotational disk.everysec — default. ~1s worst-case data loss window; the practical durability/perf sweet spot.no — kernel-driven (~30s on Linux). Fastest, weakest durability.BGREWRITEAOF manual; auto via auto-aof-rewrite-percentage 100 + auto-aof-rewrite-min-size 64mb (rewrite when AOF doubles since last rewrite and ≥ 64 MB).aof-use-rdb-preamble yes (default since Redis 4, on by default 7+). AOF starts with an RDB binary chunk, then incremental commands. Faster recovery than pure AOF, more durable than pure RDB.save "" AND appendonly no. Setting only one leaves the other active.BGSAVE/BGREWRITEAOF use fork() — Linux CoW means the child starts with shared pages but copies on write. Peak memory can transiently approach 2× RSS during heavy write traffic. Watch latest_fork_usec from INFO.maxmemory 4gb. Cgroup memory limit is independent — set both to avoid OOM-kill.maxmemory-policy (default noeviction):
noeviction — writes fail with OOM error when full. Reads still work. Default, surprises users.allkeys-lru / allkeys-lfu / allkeys-random — any key eligible.volatile-lru / volatile-lfu / volatile-random / volatile-ttl — only keys with TTL eligible. Footgun: if no keys have TTL, behaves like noeviction.maxmemory-samples keys (default 5) and evicts the worst. Bump to 10 for accuracy, 3 for speed. True LRU would require tracking every access.lfu-log-factor 10 (default) — higher = slower counter saturation; favors long-tail hot keys.lfu-decay-time 1 (default, minutes) — how fast counter decays toward 0.volatile-ttl: evicts keys with the shortest remaining TTL first. Useful when TTL encodes priority.INFO stats → evicted_keys counter. Rising fast → cap too low or wrong policy.MEMORY USAGE key [SAMPLES n] — bytes (sampling for collections).MEMORY STATS per-pool (overhead, dataset, allocator). MEMORY DOCTOR — narrative summary; flags fragmentation, child-process forks, big clients.redis-cli --bigkeys — sample-based largest-by-type. Fast, approximate.redis-cli --memkeys --memkeys-samples 0 — accurate but full-scan (heavy).redis-cli --keystats — per-type byte/length distribution.redis-cli --hotkeys — top accessed keys. Requires maxmemory-policy *-lfu (uses LFU counters).MONITOR in production: streams every command server-wide, ~50 % perf hit. Use redis-cli -i 1 -r 60 INFO commandstats for periodic sampling; diff between samples surfaces hot patterns.CLIENT TRACKING ON over RESP3), key sharding ({user:1234}:counter:{0..9} then sum), or read replicas with READONLY.INFO memory → mem_fragmentation_ratio = used_memory_rss / used_memory.
> 1.5 → real fragmentation (jemalloc holding free pages).< 1.0 → swapping (RSS smaller than logical). Investigate vmstat.activedefrag yes. Triggers when active-defrag-ignore-bytes 100mb AND active-defrag-threshold-lower 10 (% fragmentation) both met. CPU-bounded by active-defrag-cycle-min/max (1–25 % default).slowlog-log-slower-than 10000 — microseconds; default 10 ms. 0 logs every command, -1 disables.slowlog-max-len 128 — ring buffer length.SLOWLOG GET 10 last 10; SLOWLOG LEN; SLOWLOG RESET.slowlog-log-slower-than not affecting field.latency-monitor-threshold 100 — ms; 0 (default) disables.command, fast-command, fork, aof-write, aof-fsync-always, aof-stat, aof-rewrite-diff-write, rdb-unlink-temp-file, expire-cycle, eviction-cycle, eviction-del.LATENCY LATEST — most recent event per type.LATENCY HISTORY <event> — time series for one event.LATENCY GRAPH <event> — ASCII spark chart.LATENCY DOCTOR — narrative analysis with remediation hints.LATENCY RESET [event ...].MONITOR is not a diagnostic tool: streams every command to the client. ~50 % perf hit on the server. Use redis-cli -i 1 -r 60 INFO commandstats for periodic sampling instead.Cluster (sharded; horizontal scale + HA):
slot = CRC16(key) mod 16384. Each master owns a slot range. Min 3 masters for HA failover voting; recommended 6 nodes (3 master + 3 replica).CLUSTER SHARDS (Redis 7+, structured, prefer this), CLUSTER NODES (raw), CLUSTER SLOTS (legacy). Per-slot: CLUSTER COUNTKEYSINSLOT <slot> / CLUSTER GETKEYSINSLOT <slot> <count>.MOVED <slot> ip:port — permanent, refresh slot map. ASK <slot> ip:port — slot in migration, one-shot, do NOT cache. Smart clients cache the slot table and recompute on MOVED.{tag}key — only substring inside {...} is hashed. Forces same-slot routing for multi-key ops.MGET, MSET, SINTERSTORE, MULTI/EXEC, Lua EVAL — all keys must hash to same slot or CROSSSLOT error.redis-cli --cluster {create,check,fix,reshard,rebalance,info,call,import}. --cluster check finds slot coverage gaps and stuck open slots.SPUBLISH/SSUBSCRIBE route by hash slot; replaces broadcast PUBLISH which was inefficient cluster-wide.Sentinel (HA for non-sharded master + replicas):
sentinel monitor <name> <master> <port> <quorum>. quorum = sentinels that must agree master is s_down before voting starts. Election requires majority of all sentinels (distinct from quorum).sentinel down-after-milliseconds <name> <ms> — unresponsive duration before s_down (subjective). Quorum count → o_down (objective) → election.sentinel parallel-syncs <name> <N> — replicas resyncing from new master simultaneously. Default 1; higher = faster convergence, more I/O on new master.sentinel failover-timeout <name> <ms> — bounds full failover; also throttles retry on failed failover. Default 180000 (3 min).Replication (under both cluster and sentinel):
replicaof <host> <port> (or deprecated slaveof). Replica is read-only by default (replica-read-only yes).BGSAVEs an RDB, ships, replays buffered commands. Triggered on fresh replica, ID mismatch, or backlog gap. Partial (PSYNC) — replica reconnects with last offset; if master's backlog still covers it → ship the delta.repl-backlog-size — circular buffer on master holding recent writes for partial resync. Default 1mb. Too small → frequent full resyncs after any blip. Bump to 64–512 MB on busy masters with flaky networks. Cost is buffer size, master-side.repl-backlog-ttl 3600 — release backlog after N seconds with no replicas connected.min-replicas-to-write N + min-replicas-max-lag M (seconds) — master refuses writes unless ≥ N replicas have lag ≤ M.replicaof topology for read-after-write without explicit fencing.failover to a replica creates a new replication ID, forcing a full sync on any other reconnecting replica. Plan promotion windows accordingly.Pipelining vs transactions:
MULTI / EXEC / DISCARD: server queues commands after MULTI, executes batch atomically on EXEC. No interleaving. No rollback — each command's error reported but the rest still run, except queue-time syntax errors which abort the whole transaction.WATCH key [key ...] before MULTI — optimistic locking / CAS. If any watched key is modified before EXEC, EXEC returns nil and nothing runs. Retry loop is the caller's job. Best for low contention.MULTI/queued/EXEC into one TCP write.Lua and Functions:
EVAL script numkeys key1 ... arg1 ... — atomic server-side execution. KEYS/ARGV separation is mandatory; in cluster mode all KEYS must hash to same slot.EVALSHA <sha> ... after SCRIPT LOAD — caches script by SHA1. Fall back to EVAL on NOSCRIPT (cache flushed on restart / SCRIPT FLUSH).FUNCTION LOAD) — persistent server-side library, replicated and persisted. Replaces ad-hoc Lua-per-deploy; preferred for shared logic.Streams (durable log + consumer groups):
XADD stream '*' field value ... — * autogenerates <ms-timestamp>-<seq>; explicit IDs must be monotonically increasing.XADD stream MAXLEN ~ 100000 ... — ~ approximate trim (efficient), = exact (expensive). MINID trims by ID.XGROUP CREATE stream g $ MKSTREAM ($ = current end; 0 = beginning).XREADGROUP GROUP g consumer1 COUNT 10 BLOCK 5000 STREAMS stream > — > = new messages only. Use 0 to re-read this consumer's pending list (PEL recovery on restart).XREADGROUP enters PEL; remains until XACK.XPENDING stream g summary; XPENDING stream g IDLE <ms> - + count [consumer] detail.XCLAIM stream g new-consumer min-idle-ms <id> ... — reassign stuck messages.XAUTOCLAIM stream g new-consumer min-idle-ms <start-id> [COUNT n] (Redis 6.2+) — automated PEL handover. Prefer over manual XCLAIM loops.XACK causes redelivery. Track times_delivered via XPENDING; route to DLQ stream above N.Pub/Sub:
SUBSCRIBE/PUBLISH/PSUBSCRIBE — fire-and-forget, no persistence, no consumer groups. Subscribers connected at publish time get the message; everyone else loses it. For durable fan-out use Streams. In cluster, use sharded SPUBLISH/SSUBSCRIBE.ACL (Redis 6+):
default user with on nopass ~* &* +@all — full access. Set requirepass or edit default ACL to lock down.ACL SETUSER alice on >mypass ~app:* &events:* +@read +get +set -@dangerous
on/off — enable; >pw add password, <pw remove, nopass, resetpass.~pattern — key glob; multiple allowed; ~* = all; resetkeys clears.&pattern (Redis 6.2+) — Pub/Sub channel glob; allchannels / resetchannels.+cmd / -cmd / +@category / -@category.@all, @admin, @dangerous (FLUSHALL/KEYS/CONFIG/...), @write, @read, @keyspace, @connection, @scripting, @stream, @pubsub, @slow, @fast, plus per-data-type (@string, @hash, @list, @set, @sortedset, @geo, @bitmap, @hyperloglog).ACL WHOAMI, ACL LIST, ACL GETUSER alice, ACL CAT [category], ACL LOG (recent auth/permission failures).user ... lines in redis.conf OR external aclfile /path/users.acl — not both. ACL SAVE writes to aclfile (only when aclfile is set).TLS (Redis 6+): tls-port 6380, tls-cert-file, tls-key-file, tls-ca-cert-file. tls-auth-clients yes for mTLS. Compile with make BUILD_TLS=yes (not default in stock builds before 7).
CLIENT control:
CLIENT LIST [TYPE normal|master|replica|pubsub] [ID ...].CLIENT KILL ID <id> / ADDR ip:port / LADDR ip:port / TYPE x / USER alice.CLIENT NO-EVICT ON (Redis 7+) — protect this connection from maxmemory-clients eviction.CLIENT TRACKING ON (RESP3) — server-assisted client-side caching with invalidations.CONFIG:
CONFIG GET <pattern> / CONFIG SET <param> <value> — runtime change. Not all params are settable at runtime; some require restart.CONFIG REWRITE — persists in-memory config back to redis.conf, preserving comments where possible. Without it, runtime changes vanish on restart.CONFIG RESETSTAT — zeros the INFO stats counters.io_uring. Single node replaces a small Redis cluster. Wire-compatible with most commands. Caveats: Lua support limited or absent in some versions, AOF semantics differ, no exact SLOWLOG/LATENCY parity. Vet feature coverage before adopting.Official Redis docs (redis.io/docs/latest):
Source / changelog:
redis.conf defaults, CHANGELOG.md, src/replication.cCommunity deep-dives:
Variants:
Before recommending a non-trivial operational change (eviction policy, fsync, backlog size, cluster reshard, ACL, defrag):
INFO, LATENCY, SLOWLOG, evicted_keys, mem_fragmentation_ratio) — never blanket-tune.Tuning without measurement is worse than defaults.
npx claudepluginhub pvillega/claude-templates --plugin ctProvides a quick-reference guide for redis-cli: connection, security, installation, and common commands. Useful when querying, debugging, or managing Redis from the command line.
Guides Redis system design: data structures for caching, queues, leaderboards, sessions; caching strategies, pub/sub, streams, clustering, memory optimization, Lua scripting.
Redis patterns for caching, rate limiting, distributed locks, session storage, Pub/Sub, and connection management in production applications.