Git Product home page Git Product logo

Comments (3)

mike-marcacci avatar mike-marcacci commented on July 26, 2024

Hey @IvanMMM, since redis is the backing store for this, that's certainly possible. However, it's probably not what you want to do. Here's why:

Before a lock is registered with redis, it generates a cryptographically random value to distinguishes it from any other locks that may exist. When a lock is released, it checks to make sure that the current lock in redis has this exact value, before deleting it. This is super important because there can be wide fluctuations in network speed/latency, and there is an inherent race condition between a lock's expiration and a manual call to .release() or .unlock(). For example:

  1. Worker A acquires a lock for foo
  2. Worker A attempts to release its lock for foo
  3. Before worker A reaches redis, the lock expires
  4. Worker B acquires a lock for foo
  5. Worker A reaches redis, but does not release the worker B's lock because it has a different value

If you want to force the release of a resource you can simply call:

redis.del(yourResourceName)

Just be aware that this will delete any lock on that resource.

A better option would be to serialize the Lock and pass it to a worker.

from node-redlock.

IvanMMM avatar IvanMMM commented on July 26, 2024

@mike-marcacci It could be serialized, then? That's awesome! So, I guess, just create new Lock(...) and use methods after it. Thank you!

from node-redlock.

bluEEil avatar bluEEil commented on July 26, 2024

@mike-marcacci Hey, I have a similar use-case where I have on process locking the resource and a different one that should unlock it.
I don't understand exactly how I can do it safely, you said I can serialize the lock and pass it to the process that needs to unlock it or pass the generated value as the resource name so I can delete it from Redis directly?

Can you provide examples for the 2 options?

from node-redlock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.