Redis and caching checklist¶
Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).
Also apply the general checklist.
This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.
Strongly recommended (9–10)¶
-
REDIS-10(9) Set thebinddirective inredis.confto private interfaces, firewall the Redis port so that only the application hosts can reach it, and leave protected mode on. (specific/redis) Automatable: Checkov Terraform policies.
Recommended (6–8)¶
-
REDIS-1(8) Keep the authoritative copy of cached data in a durable data store, and keep data only in Redis when you have configured persistence and replication for it on purpose. (specific/redis) -
REDIS-2(8) Give cache entries a TTL, even a long one, unless write-through keeps them current, and setmaxmemorywith an eviction policy that fits the workload, such asallkeys-lrufor a pure cache. (specific/redis) -
REDIS-6(8) Never callKEYSfrom application code, and avoid other O(N) commands on big keys: iterate withSCAN,SSCAN,HSCANorZSCAN, keep collections and values small, and watch the slow log. (specific/redis) Automatable: Redis ACL command categories. -
REDIS-11(8) Authenticate every client as a named ACL user with only the commands and key patterns it needs, turn off the passwordlessdefaultuser, and use TLS for every connection that leaves the host. (specific/redis) Automatable: Checkov Terraform policies. -
REDIS-3(7) Choose the write strategy per data set: cache-aside (load on a miss, invalidate on write) as the default, and write-through where readers must see a change right after the write. (specific/redis) -
REDIS-4(7) Plan for a cold or unavailable cache: put a timeout on cache calls (OPS-3), make sure the data store can take the load of all misses or cap and shed that load, and load-test with the cache disabled. (specific/redis) -
REDIS-12(7) Choose persistence by what losing the data would cost: none for a cache you can rebuild, RDB snapshots when losing the last minutes of writes is acceptable, and AOF plus RDB for safety close to PostgreSQL's. Copy RDB snapshots off the machine at least daily. (specific/redis) Automatable: Checkov Terraform policies. -
REDIS-5(6) Protect expensive entries from cache stampedes: add random jitter to TTLs, let only one caller recompute a missing entry (request coalescing), or refresh hot entries before they expire. (specific/redis) -
REDIS-7(6) Name keys with one schema, such asapp:object-type:id[:field], with a prefix per application or tenant, and hash long natural keys instead of using them as key names. (specific/redis) Automatable: Redis ACL command categories. -
REDIS-9(6) Use Streams with consumer groups, not Pub/Sub, for messages that must not be lost. (specific/redis) -
REDIS-13(6) With replication, turn on persistence on the primary and the replicas, or stop a primary without persistence from restarting automatically. (specific/redis) -
REDIS-14(6) For automatic failover, run Sentinel, with at least three instances on machines that fail independently, or Redis Cluster, and design for lost writes. (specific/redis) Automatable: Checkov Terraform policies.
Conditional (1–5)¶
-
REDIS-8(5) On Redis Cluster, put keys that one multi-key command, transaction or script uses into the same hash slot with a hash tag, such as{user:1000}:cart, and use hash tags only where you need them. (specific/redis)