Comments (3)
Hi @dvergeylen – So sorry for the slow reply here!
So, the library expects an actual instance of Lock
for two reasons.
- The method is actually supposed to mutate its expiration to immediately invalidate it. This prevents accidentally extending a lock you are attempting to invalidate.
- More importantly, the lock
value
is what prevents a dangerous race condition. Imagine you have 2 servers, and server A gets a lock onSOME_RESOURCE
. Eventually, server A is done with the resource, and sends a request to redis to release the lock onSOME_RESOURCE
. Now, due to the asynchronous nature of network requests, it's possible that the lock expires before the request reaches and is processed by redis. It's also possible that in that time, server B is able to successfully acquire a NEW lock onSOME_RESOURCE
. If only the resource name is used in the eventually-processed "unlock" request, then it would be possible for it to prematurely release the new lock acquired by server B! To prevent this, each lock has a cryptographically randomvalue
, to make it unique. This way, the "unlock" request from server A will only succeed if the currently-held lock is the one it's attempting to release.
All that to say, you'll almost certainly want to track at least the lock's resource
and value
, if you aren't able to keep a reference to the original lock.
To unlock the resource, the "most correct" way would be:
const Redlock = require('redlock');
const savedLockResource = 'SOME RESOURCE';
const savedLockValue = 'xxxxxx';
lock = new Redlock.Lock(redlock, savedLockResource, savedLockValue, 1);
lock.unlock();
More concisely, you could get away with:
redlock.unlock({ resource: 'SOME_RESOURCE', value: 'xxxxxx' });
Hope that helps!
from node-redlock.
I could find a workaround 😸. But I am still interested if you have an elegant way to retrieve a lock from its resource name.
from node-redlock.
Hope that helps!
It does! Thank you @mike-marcacci ! 👍
from node-redlock.
Related Issues (20)
- Submitting a value for the lock
- Migration guide from 4.2.0 to 5.x?
- Redlock 4.x Compatible with Redit 7.x? HOT 1
- Unable to achieve a quorum during its retry window
- Cannot extend an already-expired lock crashes consumer pods. HOT 1
- Throw specific errors when there's an issue either acquiring or releasing the lock HOT 1
- "ioredis": "^5.3.2" incompatible with "redlock": "^5.0.0-beta.2" and "@types/redlock": "^4.0.5", HOT 2
- TypeError: client.evalsha is not a function HOT 3
- No support for redis functions
- Lock in use should throw a specific error HOT 1
- Do not wait for lock (NOWAIT)
- Release with fixed type resolution HOT 2
- Do not execute RELEASE_SCRIPT lock failed with one client
- Return resource name of lock that was not acquired in vote against error
- MOVED Error Handling in Redis Cluster Environment
- Issue with Redlock Stuck in Redis Cluster Setup
- Expiration time is in the past HOT 2
- a few issues after trying beta 5.0.0
- Configure Redis DB # explicitly? HOT 1
- Wrong acquire() lock duration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-redlock.