diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | redis/exceptions.py | 4 | ||||
-rw-r--r-- | redis/lock.py | 6 | ||||
-rw-r--r-- | tests/test_lock.py | 6 |
4 files changed, 15 insertions, 8 deletions
@@ -1,3 +1,10 @@ +* 3.0.2 (in development) + * Added a LockNotOwnedError that is raised when trying to extend or + release a lock that is no longer owned. This is a subclass of LockError + so previous code should continue to work as expected. Thanks Joshua + Harlow + * Fixed a bug in GEORADIUS that forced decoding of places without + respecting the decode_responses option. Thanks Bo Bayles * 3.0.1 * Fixed regression with UnixDomainSocketConnection caused by 3.0.0. Thanks Jyrki Muukkonen diff --git a/redis/exceptions.py b/redis/exceptions.py index 7f3034f..35bfbe5 100644 --- a/redis/exceptions.py +++ b/redis/exceptions.py @@ -60,6 +60,6 @@ class LockError(RedisError, ValueError): pass -class LockErrorNotOwned(LockError): - "Error related to lock that may have been owned being lost." +class LockNotOwnedError(LockError): + "Error trying to extend or release a lock that is (no longer) owned" pass diff --git a/redis/lock.py b/redis/lock.py index 38ab0bf..5524d7a 100644 --- a/redis/lock.py +++ b/redis/lock.py @@ -1,7 +1,7 @@ import threading import time as mod_time import uuid -from redis.exceptions import LockError, LockErrorNotOwned +from redis.exceptions import LockError, LockNotOwnedError from redis.utils import dummy @@ -190,7 +190,7 @@ class Lock(object): if not bool(self.lua_release(keys=[self.name], args=[expected_token], client=self.redis)): - raise LockErrorNotOwned("Cannot release a lock" + raise LockNotOwnedError("Cannot release a lock" " that's no longer owned") def extend(self, additional_time): @@ -211,6 +211,6 @@ class Lock(object): if not bool(self.lua_extend(keys=[self.name], args=[self.local.token, additional_time], client=self.redis)): - raise LockErrorNotOwned("Cannot extend a lock that's" + raise LockNotOwnedError("Cannot extend a lock that's" " no longer owned") return True diff --git a/tests/test_lock.py b/tests/test_lock.py index 5ad7d5c..ea45379 100644 --- a/tests/test_lock.py +++ b/tests/test_lock.py @@ -1,7 +1,7 @@ import pytest import time -from redis.exceptions import LockError, LockErrorNotOwned +from redis.exceptions import LockError, LockNotOwnedError from redis.lock import Lock @@ -85,7 +85,7 @@ class TestLock(object): lock.acquire(blocking=False) # manually change the token r.set('foo', 'a') - with pytest.raises(LockErrorNotOwned): + with pytest.raises(LockNotOwnedError): lock.release() # even though we errored, the token is still cleared assert lock.local.token is None @@ -122,7 +122,7 @@ class TestLock(object): lock = self.get_lock(r, 'foo', timeout=10) assert lock.acquire(blocking=False) r.set('foo', 'a') - with pytest.raises(LockErrorNotOwned): + with pytest.raises(LockNotOwnedError): lock.extend(10) |