redis-best-practices
Redis best practices and performance rules for production, for any Redis deployment including open source Redis, Valkey, Redis Cloud, AWS ElastiCache, Google…
от upstash★ 37 звёзд на GitHub
Установить redis-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Redis Best Practices
Rules for code that talks to Redis, on any deployment. They come from real support cases and from tests on two engines:
- Stock Redis: Redis 8 with default settings and the client on the same machine, so no network cost.
- Upstash Redis: with the client in the same region, about 1 ms away.
Engines differ. Stock Redis runs commands on one main thread, so one slow command stalls every client. Valkey, managed services and Upstash change some defaults and limits. Rules below apply everywhere unless they name an engine, and On Upstash collects what differs there.
Decide what the database is
- Cache: eviction on, and a TTL on every key.
- Store: eviction off, backups on, and a size limit raised before it is hit.
Half the trouble in support comes from databases that are neither, growing until writes fail or keys vanish. A cache with no expirations and a high miss rate only grows.
Know the eviction policy. Open source Redis defaults to noeviction, which fails writes at the limit, and some managed services default to volatile-lru. For a pure cache, use allkeys-lru or allkeys-lfu, but remember they delete keys you may not be able to reload. volatile-* policies only evict keys with a TTL, so a store without TTLs frees nothing. Eviction is sampled and approximate, so keep headroom. A database pinned at its limit evicts all day.
Batch with the right command
| Need | Use |
|---|---|
| Read many plain keys | MGET in chunks of 1,000 |
| Write many plain keys | MSET in chunks of 1,000 |
| Read many fields of one hash | HMGET |
| Mixed commands | Pipeline in chunks of 1,000 |
| All or nothing | MULTI/EXEC |
A pipeline saves round trips, never commands. MGET is one command, so it beats a pipeline of GETs wherever it fits. Reading 1,000 keys:
| Distance to the database | Await each GET |
Pipeline | MGET |
|---|---|---|---|
| Same machine (stock Redis) | 46 ms | 3.6 ms | 1.3 ms |
| 1 ms (Upstash) | 1,023 ms | 6.7 ms | 3.8 ms |
| 116 ms (Upstash) | 118,016 ms | 172 ms | 140 ms |
Always chunk. Redis queues replies in memory, and normal clients have no output buffer limit by default. While stock Redis read 200,000 keys of 1 KB, another client's slowest read was 48.8 ms during one pipeline and 73.9 ms during one MGET, against 0.84 ms and 0.51 ms in chunks of 1,000. Lower the chunk size when values are large, because reply bytes are the real cost.
A pipeline isn't atomic, so if it fails partway, the commands before the failure stay applied. On a cluster, MGET and MSET need all their keys in one slot, so use hash tags or a pipeline per node.
Details and numbers: Why MGET Is Faster Than a Redis Pipeline for Reading Many Keys
Keep keys small and bounded
- Keep values in the tens of kilobytes. Redis's own guide calls hundreds of kilobytes a big key. Put large files in object storage and keep the path in Redis, or compress on the client. One cache served 400 KiB values at 12 M reads a day, which came to over 100 TB of bandwidth a month.
- Keep collections under about 10,000 members. Split larger ones by a hash of the ID or by time bucket.
- Prefer named fields to whole collections. On stock Redis at 1 million fields,
HGETALLtook 1,126 ms and stalled another client for 96 ms, whileHMGETof 10 fields took 0.4 ms. - Delete big keys with
UNLINK. On stock Redis at 1 million fields,DELtook 319 ms and stalled another client for 314 ms, whileUNLINKtook 0.3 ms. Lazy freeing is off by default in Redis, and on by default in Valkey 8. - Bound every queue from the first write:
XADD ... MAXLEN ~ 1000orMINID,LTRIMafter everyLPUSH, and a TTL on temporary results, including anything a*STOREcommand produces. - Spread hot keys. A key lives on one shard, so adding nodes won't help it. A local cache of a few seconds is the simplest fix, then read replicas, then splitting writes across keys.
- Find problem keys with
redis-cli --bigkeys,--memkeys,--hotkeys(needs an LFU policy) andMEMORY USAGE.
Details and numbers: How Big Should a Redis Key Be?
TTLs and cache hit rate
- Put a TTL on every cache key, with
SET key value EX ttlin one command. - Add 10% jitter when many keys are written together. In a bulk load of 5,000 keys, it cut peak misses per second from 1,687 to 760 on stock Redis and from 1,683 to 779 on Upstash, which protects the database behind the cache. Total misses stay about the same, so a higher hit rate needs a longer TTL.
- Set jitter in milliseconds on short TTLs, or rounding removes it.
- Protect a single hot key with a lock or stale-while-revalidate, since jitter spreads many keys and one key still expires at one moment. See the thundering herd guide.
- Cache negative results with a sentinel and a short TTL, or keep
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл redis-best-practices?
Redis best practices and performance rules for production, for any Redis deployment including open source Redis, Valkey, Redis Cloud, AWS ElastiCache, Google Memorystore, Azure Cache, and Upstash. Use when writing, reviewing, or debugging Redis code for performance or scale, when choosing between pipeline and MGET, KEYS and SCAN, or WATCH and Lua, or when the user mentions Redis best practices, Redis performance, slow Redis, Redis latency, high memory use, a high Redis bill, big keys, hot keys, large hashes, HGETALL, cache hit rate, TTL jitter, key expiration, cache stampede, maxmemory and eviction policies, unbounded lists or streams, XACK and consumer groups, pub/sub vs streams, Lua script blocking, key-based locking for Lua scripts, connection pooling, serverless connections, retries and timeouts, replication lag, ACL users, credential rotation, or Redis monitoring. Also explains errors such as OOM command not allowed, BUSY Redis is busy running a script, NOSCRIPT, CROSSSLOT, and Upstash limit errors.
Как установить скилл redis-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл redis-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…