Closed tshubham19 closed 1 year ago
At the moment, you cannot, but could you just share the Lock
instance across threads (protected by a mutex, obviously)? Happy to accept a PR where a Lock can be created from a key.
I created a PR that should (hopefully) make it possible.
What If I want to release form another process ? I cannot share it. It would be super helpful in a replicated application environment
@timo-klarshift you can use my fork.
Instead of the regular Obtain, call it like this:
// Try to obtain lock.
locker.Obtain(ctx, "my-key", 150*time.Millisecond, &redislock.Options{
Secret: "test",
})
If the second application uses the same secret, it will be able to obtain (and release) the lock.
@timo-klarshift @janosmiko I would be more than happy to incorporate your fork into our version, but I still don't understand how locking and releasing from separate processes can be beneficial. I can see many side-effects from having a shared Secret
. Could you please explain the use case where this may be beneficial? Normally, you would want a distributed lock so that multiple processes don't perform the same task concurrently.
I tried to explain my use case in the PR. But here's a pretty simple one:
So to confirm, this is purely to prevent process/application A from waiting when trying to re-acquire the lock in step 3?
The idea is to make it possible to release the lock from other processes. In this case, in step 3 the application is able to obtain (and release) the previous lock.
@janosmiko Please see #66
@dim looks solid to me :) any idea on timing for the release?
just judging whether i should roll my own temporarily for now, cheers
@sambarnes sorry, forgot about this, will release today
@dim legend 🙇
Hey! @dim I think I'm missing something but I can not quite comprehend how this PR (https://github.com/bsm/redislock/pull/66) solves the issue. @janosmiko checks in his fork (https://github.com/janosmiko/redislock/blob/main/redislock.go see line 116) whether the stored value equals the value that should be stored. If this is the case it means the process trying to obtain the lock knows the shared secret/token (whatever you wanna call it;-)) and is allowed to reobtain it. Where is this done in your code?
@michatw good point, missed this
@michatw is this what you had in mind https://github.com/bsm/redislock/pull/71?
@michatw is this what you had in mind #71?
@dim LGTM. Thanks for your fast response!
This is not an issue, just a question. How do we get lock having just a key value. We need this option in the scenarios when we acquire a lock in a thread and try to release the same lock in the other thread. Thanks team,