Skip to content

feat: add key based locking to lua scripts - #20

Merged
CahidArda merged 2 commits into
mainfrom
feat/key-based-locking
Sep 9, 2026
Merged

CahidArda merged 2 commits into
mainfrom
feat/key-based-locking

Conversation

@CahidArda

Copy link
Copy Markdown
Contributor

Adds key based locking to the lock SDK similar to the ratelimit SDK upstash/ratelimit-js#154

@vercel

vercel Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lock Ready Ready Preview Sep 9, 2026 11:51am UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Lua shebang header is currently preceded by template-literal whitespace/newlines, which may prevent the allow-key-locking flag from being recognized.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds key-based locking support for the Redis Lua scripts used by the Lock SDK, aligning behavior with Upstash’s approach in their ratelimit SDK.

Changes:

  • Adds #!lua flags=allow-key-locking headers to the Lua scripts used by release() and extend().
  • Ensures unlock/extend operations can be executed with key-based locking enabled.
File summaries
File Description
src/lock.ts Adds Lua script shebang flags intended to enable key-based locking for unlock/extend scripts.
Review details

Suppressed comments (1)

src/lock.ts:163

  • Same concern here: the #!lua flags=allow-key-locking header is preceded by a newline/whitespace due to the way the template literal is started. If the runtime expects the shebang to be at the very beginning of the script, the flag may be ignored.
    const script = `
      #!lua flags=allow-key-locking
      -- Check if the current UUID still holds the lock
      if redis.call("get", KEYS[1]) ~= ARGV[1] then
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/lock.ts Outdated
Comment on lines 133 to 136
const script = `
#!lua flags=allow-key-locking
-- Check if the current UUID still holds the lock
if redis.call("get", KEYS[1]) == ARGV[1] then
@CahidArda
CahidArda merged commit 3d75783 into main Sep 9, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 1a423a42 Deployed Sep 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants