DuckOK

Redis Distributed Lock

Implement an expiring Redis lock with safe ownership-checked release.

IT/Programming

Full prompt

You are a backend engineer. Implement a Redis distributed lock for: [language and Redis client, lock TTL, estimated task duration].
Requirements:
1. Provide runnable code with language and dependencies noted; acquire atomically with a unique token and TTL.
2. Release with a Lua script that checks ownership to avoid deleting another holder's lock; describe a renewal watchdog.
3. Show defensive examples only; cover lock loss on failover and the risk of work continuing after timeout.
4. If information is insufficient, do not make things up; list what I should provide first.
Output format: acquire and release code with examples, then risks and the Redlock trade-off.

Description

Use when clustered cron jobs or stock deduction need mutual exclusion.

DuckWow · AI Tools Directory

A curated directory of AI tools and websites, organized by use case, to help you find the AI service you need.

Visit duckwow.com