Redis lock recheck flag pattern
Skill kjuhwa/skills-hub/skills/backend/redis-lock-recheck-flag-pattern
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill redis-lock-recheck-flag-patternAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Distributed Redis lock with a "recheck" flag so concurrent events arriving while the lock is held force the holder to run a second pass, instead of being silently dropped.
SKILL.md
1.9 KB, 383 tokens by cl100k_base, as published. Nobody here has run it
Redis Lock + Recheck Flag
Shape
lockKey = prefix:<key>
recheckKey = recheck:<key>
instanceId = <hostname>:<uuid>
Acquire via SET lockKey instanceId NX EX ttl. If acquired, loop: clear recheck → run work → if recheck was re-set during work, loop again. On exit, release with a Lua script that only deletes if the current value matches instanceId (prevents stealing).
Steps
- Compute
lockKey,recheckKey,instanceId. SET lockKey instanceId NX EX ttl.- Acquire failed →
SET recheckKey 1and return. (Signals the holder: reprocess after done.) - Acquire succeeded → enter process loop:
DEL recheckKey(clear before work).- Run business logic.
EXISTS recheckKey? If yes, loop. Else break. (Cap withMAX_LOOPSto prevent starvation.)
- Release with Lua:
if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) end return 0
Counter / Caveats
- Choose TTL > worst-case processing time. If it expires mid-run, another instance grabs the lock — two workers.
DEL recheckKeymust happen before work, not after, or events arriving during work are lost.- Cap the retry loop so a continuously-racing event stream can't pin one instance forever.
- Use a UUID-per-invocation for
instanceId, not a static hostname — otherwise two worker threads on the same host can't tell their locks apart.
What ships with it: 1 file
418 B alongside SKILL.md
- content.md418 B