{"id":45528,"library":"nestjs-fifo-lock","title":"nestjs-fifo-lock","description":"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.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/MRezaBaiat/nestjs-fifo-lock","tags":["javascript","typescript"],"install":[{"cmd":"npm install nestjs-fifo-lock","lang":"bash","label":"npm"},{"cmd":"yarn add nestjs-fifo-lock","lang":"bash","label":"yarn"},{"cmd":"pnpm add nestjs-fifo-lock","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Uses NestJS decorators and module system","package":"@nestjs/common","optional":false},{"reason":"Required for Redis client to manage locks","package":"ioredis","optional":false},{"reason":"Used to generate unique lock request IDs","package":"uuid","optional":false}],"imports":[{"note":"CommonJS require works but ESM import is preferred for TypeScript projects.","wrong":"const LockModule = require('nestjs-fifo-lock').LockModule;","symbol":"LockModule","correct":"import { LockModule } from 'nestjs-fifo-lock';"},{"note":"The decorated function must be async; UseLock is a method decorator.","wrong":"import { UseLockDecorator } from 'nestjs-fifo-lock';","symbol":"UseLock","correct":"import { UseLock } from 'nestjs-fifo-lock';"},{"note":"Type import for configuration options; only available with TypeScript.","wrong":"import { LockOptions } from 'nestjs-fifo-lock';","symbol":"IFifoLockOptions","correct":"import { IFifoLockOptions } from 'nestjs-fifo-lock';"},{"note":"Direct import from package entry; no need to specify '/dist'.","wrong":"import { FifoLockService } from 'nestjs-fifo-lock/dist';","symbol":"FifoLockService","correct":"import { FifoLockService } from 'nestjs-fifo-lock';"}],"quickstart":{"code":"// app.module.ts\nimport { Module } from '@nestjs/common';\nimport { LockModule } from 'nestjs-fifo-lock';\n\n@Module({\n  imports: [\n    LockModule.register({\n      redisHost: process.env.REDIS_HOST ?? 'localhost',\n      redisPort: parseInt(process.env.REDIS_PORT ?? '6379'),\n      lockMaxTTL: 60000,\n      healthCheckInterval: 60000,\n      lockAcquireInterval: 500,\n      maxExtensions: 5\n    })\n  ]\n})\nexport class AppModule {}\n\n// some.service.ts\nimport { Injectable } from '@nestjs/common';\nimport { UseLock } from 'nestjs-fifo-lock';\n\n@Injectable()\nexport class SomeService {\n  @UseLock((args) => ({ type: 'user', tag: args.userId }))\n  async processUser(userId: string): Promise<void> {\n    // Critical section - only one instance processes this user at a time\n    console.log(`Processing user ${userId}`);\n  }\n}\n","lang":"typescript","description":"Demonstrates LockModule registration with Redis connection and UseLock decorator on a service method."},"warnings":[{"fix":"Ensure the decorated method returns a Promise (async).","message":"UseLock decorator must be applied to async functions only; synchronous functions will not work as the lock acquires asynchronously.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use NTP or similar clock sync across all instances.","message":"Clock synchronization between servers is required for the FIFO order to be correct; if server clocks drift, locks may be granted out of order.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use rest parameters or argument destructuring: @UseLock((...args) => ({ type: 'x', tag: args[0].id }))","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use LockModule.register() as per current documentation.","message":"Older versions may have used a different signature for LockModule.register (e.g., forRoot vs register).","severity":"deprecated","affected_versions":">=0.0.0 <1.0.0"}],"env_vars":null,"search_vec":"'1.0.6':16 'access':67 'across':32 'applic':63 'argument':60 'base':21,57 'built':38 'built-in':37 'check':41 'configur':46 'current':13 'decor':20 'decorator-bas':19 'differenti':36 'distribut':22,69 'dynam':54 'ensur':25 'environ':70 'extens':49 'fifo':3,6 'first':27,29 'first-in-first-out':26 'function':59 'health':40 'implement':8 'instanc':34 'javascript':71 'key':35,56 'limit':50 'lock':4,7,23,45,55 'mechan':24 'multipl':33 'nestj':2,10,62 'nestjs-fifo-lock':1 'order':31,65 'provid':17 'redi':12 'requir':64 'resourc':66 'stabl':14 'stale':44 'support':52 'sweeper':42 'target':61 'ttl':47 'typescript':72 'use':11 'version':15","created_at":"2026-06-07T12:55:27.571933+00:00","updated_at":"2026-06-07T12:55:27.571933+00:00","problems":[{"fix":"Start Redis or check your RedisHost and redisPort config.","cause":"Redis server is not running or host/port incorrect.","error":"Error: connect ECONNREFUSED ::1:6379"},{"fix":"Use: import { UseLock } from 'nestjs-fifo-lock';","cause":"Incorrect import; possibly importing from wrong path or using CommonJS without proper default import.","error":"TypeError: UseLock is not a function"},{"fix":"Ensure redisHost and redisPort are provided in the config object.","cause":"The provided options to LockModule.register are missing required fields (redisHost, redisPort).","error":"Error: LockModule is not a NestJS module"},{"fix":"Run: npm install nestjs-fifo-lock","cause":"Package not installed or version incompatible with Node.js modules.","error":"Error: Cannot find module 'nestjs-fifo-lock'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/MRezaBaiat/nestjs-fifo-lock#readme","github":"https://github.com/MRezaBaiat/nestjs-fifo-lock","docs":null,"changelog":null,"pypi":null,"npm":"nestjs-fifo-lock","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}