danielstjules / redislock

Node distributed locking using redis
MIT License
110 stars 32 forks source link

will this work in a multi-node redis cluster? #10

Closed lakamsani closed 7 years ago

lakamsani commented 7 years ago

Hi, thanks for making this available. I started with the patterns on https://redis.io/commands/set, after some googling found yours.

Will it work in a cluster? Like this: https://redis.io/topics/cluster-tutorial or this: https://aws.amazon.com/elasticache/ (in cluster mode)

I 'm assuming this is not an implementation of https://redis.io/topics/distlock?

danielstjules commented 7 years ago

I would not use this library's locks with redis cluster. It might seem to work by only performing operations on the master, and not the slaves (since propagation is async, and reads might be stale from the slaves) But if the master fails after acknowledging a write (acquiring lock) and before syncing the slaves, then the write (and lock) vanishes into the ether when a new master is elected.

I believe this library was written a few months before redlock was published. However, it does implement the algorithm outlined at https://redis.io/topics/distlock under "Correct implementation with a single instance" Might be worth evaluating tradeoffs for what you're working on! For stronger guarantees, might also be worth looking at ZooKeeper.

Hope that helps!

lakamsani commented 7 years ago

thx for your feedback. might try this first before going to ZooKeeper. https://github.com/mike-marcacci/node-redlock