Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Invalidate Redis namespaces with cursor scanning and asynchronous deletion
For one-off Redis namespace cleanup, enumerate exact keys with SCAN and delete bounded batches with UNLINK. Document and track the operation separately from deploying the code fix.
Bad example
| 1 | const keys = await redis.keys('feed:topic:*'); |
| 2 | await redis.del(keys); |
Explanation (EN)
A wildcard passed to DEL is a literal key, while KEYS can block on a large keyspace.
Objašnjenje (HR)
Wildcard proslijeđen DEL-u običan je naziv ključa; KEYS može blokirati velik prostor ključeva.
Good example
| 1 | let cursor = '0'; |
| 2 | do { |
| 3 | const page = await redis.scan(cursor, 'MATCH', 'feed:topic:*', 'COUNT', 100); |
| 4 | cursor = page[0]; |
| 5 | for (let i = 0; i < page[1].length; i += 100) { |
| 6 | await redis.unlink(...page[1].slice(i, i + 100)); |
| 7 | } |
| 8 | } while (cursor !== '0'); |
Explanation (EN)
Bound the operation and preserve the active data contract.
Objašnjenje (HR)
Ograniči operaciju i očuvaj ugovor za aktivne podatke.
Notes (EN)
For authorized operational cleanup, verify instance/database and namespace, scan to cursor zero and unlink bounded batches, accounting for cluster primaries and concurrent writers.
Bilješke (HR)
Za odobreno operativno čišćenje provjeri instancu, bazu i namespace. Skeniraj do povratka kursora na nulu i briši ograničene pakete pomoću UNLINK, uz provjeru cluster primarnih čvorova i istodobnih upisa.
Exceptions / Tradeoffs (EN)
For a single known small key, DEL may be acceptable. Confirm UNLINK support on older Redis installations. SCAN can return duplicate keys or an empty batch before completion and is not a point-in-time snapshot. Coordinate generation/rollout and revalidation; never infer completion from one empty page.
Iznimke / Tradeoffi (HR)
DEL može biti prihvatljiv za jedan poznati mali ključ. Provjeri podržava li stari Redis UNLINK. SCAN može vratiti duplikate ili praznu stranicu prije završetka i ne daje snimku jednog trenutka. Uskladi generacije, objavu i ponovnu provjeru; jedna prazna stranica nije dokaz završetka.