ionelmc / python-redis-lock

Lock context manager implemented via redis SET NX EX and BLPOP.
https://pypi.python.org/pypi/python-redis-lock
BSD 2-Clause "Simplified" License
551 stars 77 forks source link

Is it possible to set parameter for acquire? #67

Open Twbadkid opened 5 years ago

Twbadkid commented 5 years ago

Hi,
In redis_lock/__init__.py line: 341

def __enter__(self):
    acquired = self.acquire(blocking=True)

blocking will always be True when we use cache.lock in with block, Is it possible to set the parameter(blocking/timeout) from __init__ function or another function?

ionelmc commented 5 years ago

So you would like this code:

with Lock(blocking=False):
    something

raise an exception and skip the something?

ionelmc commented 5 years ago

An alternative api that doesn't mess with the __init__ could be:

with Lock().acquire_context(blocking=False):
    something
Twbadkid commented 5 years ago

So you would like this code:

with Lock(blocking=False):
    something

raise an exception and skip the something?

Yes.
Is it possible to add any of these solutions in this library?

tavor118sn commented 2 years ago

@ionelmc Any chance to implement this? I can make a PR if you will review and merge

ionelmc commented 2 years ago

@tavor118sn sure, please make that PR.