npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-fifo-lock

v1.0.3

Published

A fifo lock using redis and nestjs

Downloads

165

Readme

NestJS FIFO Lock

An optimized and fast "First In First Out" lock built on top of the redis and nestjs

Installation

$ npm install nestjs-fifo-lock

Usage

To use it first you will need to import the module

import { LockModule } from 'nestjs-fifo-lock';

@Module({
imports:[{
  LockModule.register({
    redisHost: 'localhost',
    redisPort: 6379,
    lockMaxTTL: 60000,
    healthCheckInterval: 60000,
    lockAcquireInterval: 500,
    maxExtensions: 5
  })
  ...
}])

and then simply add a decorator to absolutely any async function you wish

import { UseLock } from 'nestjs-fifo-lock';

//single lock

@UseLock(({field1})=>({type :'general',tag: field1.id}))
async function doSmtSerious(data:{field1}){
  ...
}

// or an array of lock contexts

@UseLock(({field1,field2})=>([{type :'general',tag: field1.id},{type :'general',tag: field2.id}]))
async function doSmtSerious(data:{field1,field2}){
  ...
}

When calling the function decorated with this param , arguments of that function will also be passed to the call back of UseLock , granting you access to the function's arguments so you can use them to determine lock queue's name.

To make sure the lock does not linger in the redis after the requester service has gone down for any reason , a health check sweeper is built internally which runs every healthCheckInterval milliseconds and will delete the lock requests older than lockMaxTTL milliseconds

Hint

Please note if using on multiple server instances connected to the same redis instance , make sure they have their time and dates in sync

Params

| Project | requirement | Description | |---------------------|---------------------------------------------|------------------------------------------------------------------------------| | redisHost | required | Redis's address | | redisPort | required | Redis's port | | lockMaxTTL | optional , defaulted to 600000 milliseconds | The time it takes before the internal healthcheck's sweeper deletes the lock | | healthCheckInterval | optional, defaulted to 600000 milliseconds | The interval for how often the healthcheck should run | | lockAcquireInterval | [ optional , default to 500 milliseconds | The interval for how often a lock in queue should check to see if it's turn | | maxExtensions | [ optional , default to 5 | How many times can an acquired lock extend after lockMaxTTL is reached |

Credits

Special thanks to my dear friend , Godwin Odo Kalu