From dfd271c92d86331672b310e06be483d7eca1c17c Mon Sep 17 00:00:00 2001 From: "Stephane Angel (Twidi)" Date: Wed, 16 Dec 2015 17:18:55 +0100 Subject: [PATCH 1/2] Resolve a redis-py bug with decode_responses=True cf https://github.com/andymccurdy/redis-py/issues/694 --- limpyd/database.py | 19 +++++++++++++++++++ limpyd/fields.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/limpyd/database.py b/limpyd/database.py index 17d4236..1fb5e48 100644 --- a/limpyd/database.py +++ b/limpyd/database.py @@ -129,3 +129,22 @@ def has_scripting(self): except: self._has_scripting = False return self._has_scripting + + +class Lock(redis.client.Lock): + """ + Override the default Lock class to manage the fact that we use ``decode_responses=True`` + but it is not taken into account in python 3 with redis 2.10, as the lock token in + ``threading.local`` is saved as ``bytes`` but the value retrieved from redis is decoded. + So the equal check doesn't work. + So we decode the value in ``threading.local`` to make this check work. + See https://github.com/andymccurdy/redis-py/issues/694 + """ + + def do_release(self, expected_token): + + if isinstance(expected_token, bytes) and \ + self.redis.connection_pool.connection_kwargs.get('decode_responses', False): + expected_token = expected_token.decode() + + super(Lock, self).do_release(expected_token) diff --git a/limpyd/fields.py b/limpyd/fields.py index d00236d..ec57bfe 100644 --- a/limpyd/fields.py +++ b/limpyd/fields.py @@ -9,8 +9,8 @@ from copy import copy from redis.exceptions import RedisError -from redis.client import Lock +from limpyd.database import Lock from limpyd.utils import make_key, normalize from limpyd.exceptions import * From 520ee8e2d5d4ff80dcd2ff27774f8c559de3d3fe Mon Sep 17 00:00:00 2001 From: "Stephane Angel (Twidi)" Date: Wed, 16 Dec 2015 17:27:56 +0100 Subject: [PATCH 2/2] Bump to version 0.2.4 --- CHANGELOG | 4 ++++ limpyd/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6cbb8dd..56e7500 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +V 0.2.4 2015-12-16 + + * Locally solve a locking bug in redis-py + V 0.2.3 2015-12-16 * Compatibility with Redis-py 2.10 diff --git a/limpyd/__init__.py b/limpyd/__init__.py index 4b744a4..86ebc6a 100644 --- a/limpyd/__init__.py +++ b/limpyd/__init__.py @@ -2,7 +2,7 @@ power and the control of the Redis API, in a limpid way, with just as abstraction as needed.""" -VERSION = (0, 2, 3) +VERSION = (0, 2, 4) __author__ = 'Yohan Boniface' __contact__ = "yb@enix.org"