Closed bolshoydi closed 3 years ago
Thanks for the report, I will look into this.
I have updated your script so that it does not continue to add more log handlers each time you call self.log
Daniel
Ok, this is the expected behavior. Because for the lock and unlock script we set an identifier, if the identifier does not match, then we do not unlock the key, and instead error.
So the thing you are trying to do here, cannot be done. You cannot change the values inside of the lock.
Thanks for response. I thought, that we acquiring lock
for redis key, not for connection checking. so name of lock should be different from keys you are stroring in redis.
As for me, it is not so obvious and that fact doesn't pointed out in any docs.
curr_lock = await self.redlock.lock('KEY_WHICH_NEVER_APPEARS_INYOUR_REAL_KEYS', lock_timeout=1)
self.redis.set('another_key','value') self.redis.get('another_key_123') self.redis.delete('another_key_456')
await self.redclock.unlock(curr_lock)
ahh no, you don't need redlock for that. you can just do setnx.
https://redis.io/commands/setnx
This will return a 1 or 0 whether it was set or not, if it was set, you get a 1 back, and you know you have a "lock" on that key. You can also set an expire on that key after the fact.
https://redis.io/commands/expire
So that they key is not held onto forever.
The purpose for redlock is for stuff where you want to manage something like a processing lock for a multi threaded application. So if you write an application and you have a bunch of project ids. You can create a lock on that project id, and all of your other processes check if the project for a message is already locked, and if it is, then your application moves on to the next message, until the project is unlocked by either being unlocked, or the lock in redis expiring.
Here is another explaination of distributed locks https://redis.io/topics/distlock
python == 3.7.6 aioredis==1.3.1 aioredlock==0.5.2
After acquiring
lock
and makingsetex
on that resource I am unable to release lock. Neither fromunlock
method nor from context manger.example code: