diff --git a/gluon/contrib/redis_cache.py b/gluon/contrib/redis_cache.py index 110360eb..6241fbcf 100644 --- a/gluon/contrib/redis_cache.py +++ b/gluon/contrib/redis_cache.py @@ -159,13 +159,15 @@ class RedisClient(object): lock_key = '%s:__lock' % newKey randomvalue = time.time() al = acquire_lock(self.r_server, lock_key, randomvalue) - # someone may have computed it - obj = self.r_server.get(newKey) - if obj is None: - value = self.cache_it(newKey, f, time_expire) - else: - value = pickle.loads(obj) - release_lock(self, lock_key, al) + try: + # someone may have computed it + obj = self.r_server.get(newKey) + if obj is None: + value = self.cache_it(newKey, f, time_expire) + else: + value = pickle.loads(obj) + finally: + release_lock(self, lock_key, al) else: # without distributed locking value = self.cache_it(newKey, f, time_expire)