Registry / devops / nestjs-fifo-lock

nestjs-fifo-lock

JSON →
library1.0.6jsnpmunverified

A FIFO lock implementation for NestJS using Redis. Current stable version: 1.0.6. Provides a decorator-based distributed locking mechanism ensuring first-in-first-out order across multiple instances. Key differentiators: built-in health check sweeper for stale locks, configurable TTL and extension limits, and support for dynamic lock keys based on function arguments. Targets NestJS applications requiring ordered resource access in distributed environments.

npm install nestjs-fifo-lock
INSTALL
IMPORT
SIG · NESTJS-FIFO-LOCK
N
nestjs-fifo-lock
devopsjavascriptv1.0.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LockModule
import { LockModule } from 'nestjs-fifo-lock';
const LockModule = require('nestjs-fifo-lock').LockModule;
CommonJS require works but ESM import is preferred for TypeScript projects.
UseLock
import { UseLock } from 'nestjs-fifo-lock';
import { UseLockDecorator } from 'nestjs-fifo-lock';
The decorated function must be async; UseLock is a method decorator.
IFifoLockOptions
import { IFifoLockOptions } from 'nestjs-fifo-lock';
import { LockOptions } from 'nestjs-fifo-lock';
Type import for configuration options; only available with TypeScript.
FifoLockService
import { FifoLockService } from 'nestjs-fifo-lock';
import { FifoLockService } from 'nestjs-fifo-lock/dist';
Direct import from package entry; no need to specify '/dist'.

Demonstrates LockModule registration with Redis connection and UseLock decorator on a service method.

// app.module.ts import { Module } from '@nestjs/common'; import { LockModule } from 'nestjs-fifo-lock'; @Module({ imports: [ LockModule.register({ redisHost: process.env.REDIS_HOST ?? 'localhost', redisPort: parseInt(process.env.REDIS_PORT ?? '6379'), lockMaxTTL: 60000, healthCheckInterval: 60000, lockAcquireInterval: 500, maxExtensions: 5 }) ] }) export class AppModule {} // some.service.ts import { Injectable } from '@nestjs/common'; import { UseLock } from 'nestjs-fifo-lock'; @Injectable() export class SomeService { @UseLock((args) => ({ type: 'user', tag: args.userId })) async processUser(userId: string): Promise<void> { // Critical section - only one instance processes this user at a time console.log(`Processing user ${userId}`); } }
Debug
Known issues
gotchaUseLock decorator must be applied to async functions only; synchronous functions will not work as the lock acquires asynchronously.
fix
Ensure the decorated method returns a Promise (async).
affects: >=1.0.0
gotchaClock synchronization between servers is required for the FIFO order to be correct; if server clocks drift, locks may be granted out of order.
fix
Use NTP or similar clock sync across all instances.
affects: >=1.0.0
gotchaThe lock argument callback receives the method's arguments directly; if the method has multiple arguments, they are passed as separate parameters, not as a single object.
fix
Use rest parameters or argument destructuring: @UseLock((...args) => ({ type: 'x', tag: args[0].id }))
affects: >=1.0.0
deprecatedOlder versions may have used a different signature for LockModule.register (e.g., forRoot vs register).
fix
Use LockModule.register() as per current documentation.
affects: >=0.0.0 <1.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED ::1:6379
Redis server is not running or host/port incorrect.
fix
Start Redis or check your RedisHost and redisPort config.
TypeError: UseLock is not a function
Incorrect import; possibly importing from wrong path or using CommonJS without proper default import.
fix
Use: import { UseLock } from 'nestjs-fifo-lock';
Error: LockModule is not a NestJS module
The provided options to LockModule.register are missing required fields (redisHost, redisPort).
fix
Ensure redisHost and redisPort are provided in the config object.
Error: Cannot find module 'nestjs-fifo-lock'
Package not installed or version incompatible with Node.js modules.
fix
Run: npm install nestjs-fifo-lock
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies
@nestjs/commonrequiredUses NestJS decorators and module system
ioredisrequiredRequired for Redis client to manage locks
uuidrequiredUsed to generate unique lock request IDs
Agent activity
2 hits · last 30 days
node
2
Resources
nestjs-fifo-lock — npm install nestjs-fifo-lock · libregistry