Skip to content

feat(nestjs-tools-lock)!: replace redlock with redlock-universal - #215

Open
legreffier[bot] wants to merge 2 commits into
mainfrom
feat/lock-redlock-universal
Open

legreffier[bot] wants to merge 2 commits into
mainfrom
feat/lock-redlock-universal

Conversation

@legreffier

@legreffier legreffier Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Replaces redlock, whose 5.0 release never left beta and is superseded per the @sesamecare-oss/redlock README, with redlock-universal 0.8.

Breaking: releases as @getlarge/nestjs-tools-lock@2.0.0 (nx release --dry-run resolves major).

Why a major

The 1.x public API exposes redlock types directly. redlock-universal uses a different model (per-key locks, a plain LockHandle, boolean release and extend), so identical types are not possible.

To keep migration small, the members people use keep their names:

1.x 2.0
lock() / get() → redlock Lock → AcquiredLock { key, value, ttl, release(), extend(ttl) }
lock.release() → ExecutionResult → boolean (false if expired or taken)
lock.extend(ttl) → Lock → boolean
unlock(key, id) → ExecutionResult → boolean
throws redlock ExecutionError throws LockAcquisitionError (re-exported)
optimistic(cb(RedlockAbortSignal)) optimistic(cb(LockAbortSignal)), same shape
LockOptions = Partial<redlock Settings> { retryCount?, retryDelay? }, same semantics
public redlock property, errorHandler() removed

Dropped options:

  • driftFactor: multi-node only. We connect to one Redis, so this uses createLock (single-node) rather than RedLock.
  • retryJitter
  • automaticExtensionThreshold: optimistic() auto-extends.
  • retryCount: -1

Other changes

  • Types (LockServiceOptions, LockOptions, AcquiredLock, LockAbortSignal) are now exported from the package index. Before, public signatures referenced them without exporting them.
  • README rewritten. The old one documented { unlock } and an optimist() method that did not exist. It now includes a migration section.
  • Removed the redlock tsconfig paths workaround and the ioredis-mock devDependency. The mock cannot run redlock-universal's Lua scripts, so tests use the real Redis that CI already provides.
  • Test Redis URL and port can be overridden with REDIS_URL / REDIS_PORT for local runs.

Verification

  • Clean typecheck, build and lint for all 8 projects; nx format:check and nx sync:check pass.
  • 14/14 lock tests, run twice against a throwaway Redis, with new coverage for extend, optimistic and retry-until-released.
  • nx release --dry-run --projects=nestjs-tools-lock → 2.0.0.

redlock 5 never left beta and is superseded by redlock-universal.
LockService now uses a per-key lock over an ioredis adapter and returns
an AcquiredLock { key, value, ttl, release(), extend() }.

BREAKING CHANGE: lock() and get() return an AcquiredLock instead of
redlock's Lock; release(), extend() and unlock() resolve to booleans;
acquisition failures throw LockAcquisitionError instead of redlock's
ExecutionError; lock options are limited to retryCount and retryDelay
(retryCount -1 is no longer supported); the public redlock property and
errorHandler() were removed. See the package README for migration.

MoltNet-Diary: e2dd9f2a-2432-494d-ba64-c75c29b45982
Task-Group: lock-redlock-universal
Task-Completes: true
@nx-cloud

nx-cloud Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit d96edc6

Command Status Duration Result
nx affected -t lint,typecheck,test,build --para... ✅ Succeeded 13s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-26 13:00:45 UTC

…universal's

LockError (with key and cause) and its subclasses LockAcquisitionError,
LockReleaseError and LockExtensionError replace the re-exported
redlock-universal errors, so no public type depends on the lock library.

MoltNet-Diary: 4cdcfbbd-a0e6-4fc9-a5eb-f6f05c806ea3
Task-Group: lock-redlock-universal

This branch has not been deployed

No deployments
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.

0 participants