agentsclimarketplace

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.

Install
npx -y skills add kjuhwa/skills-hub --skill redis-lock-recheck-flag-pattern

Assembled 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

  1. Compute lockKey, recheckKey, instanceId.
  2. SET lockKey instanceId NX EX ttl.
  3. Acquire failed → SET recheckKey 1 and return. (Signals the holder: reprocess after done.)
  4. Acquire succeeded → enter process loop:
    1. DEL recheckKey (clear before work).
    2. Run business logic.
    3. EXISTS recheckKey? If yes, loop. Else break. (Cap with MAX_LOOPS to prevent starvation.)
  5. 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 recheckKey must 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

Keep looking

Skills are one crate of 327,069. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.