Commits

Mike Bayer  committed b455e55

- re-test redis lock, its OK
- 0.5.0 version number
- some additional document updates, changelog

  • Participants
  • Parent commits 330b605

Comments (0)

Files changed (4)

File docs/build/changelog.rst

 
     .. change::
         :tags: feature
+
+      Now using the ``Lock`` included with the Python
+      ``redis`` backend, which adds ``lock_timeout``
+      and ``lock_sleep`` arguments to the :class:`.RedisBackend`.
+
+    .. change::
+        :tags: feature
         :tickets: 33
 
       Added new methods :meth:`.CacheRegion.get_or_create_multi`

File dogpile/cache/api.py

     def get_multi(self, keys): #pragma NO COVERAGE
         """Retrieve multiple values from the cache.
 
-        The returned value should be a map.
+        The returned value should be a list, corresponding
+        to the list of keys given.
 
-        .. versionadded:: 0.4.4
+        .. versionadded:: 0.5.0
 
         """
         raise NotImplementedError()
         The value will always be an instance
         of :class:`.CachedValue`.
 
-        .. versionadded:: 0.4.4
+        .. versionadded:: 0.5.0
 
         """
         raise NotImplementedError()
         regardless of whether or not the
         key exists.
 
-        .. versionadded:: 0.4.4
+        .. versionadded:: 0.5.0
 
         """
         raise NotImplementedError()

File dogpile/cache/backends/redis.py

 from __future__ import absolute_import
 from dogpile.cache.api import CacheBackend, NO_VALUE
 from dogpile.cache.compat import pickle
-import random
-import time
 
 redis = None
 
-__all__ = 'RedisBackend', 'RedisLock'
+__all__ = 'RedisBackend'
 
 
 class RedisBackend(CacheBackend):
      When left at False, dogpile will coordinate on a regular
      threading mutex.
 
-    """
-
-    # TODO: when lock works
-    #:param lock_timeout: integer, number of seconds after acquiring a lock that
-    # Redis should expire it.
+    :param lock_timeout: integer, number of seconds after acquiring a lock that
+     Redis should expire it.
 
-    #:param lock_sleep: integer, number of seconds to sleep when failed to
-    # acquire a lock.
+    :param lock_sleep: integer, number of seconds to sleep when failed to
+     acquire a lock.
+    """
 
     def __init__(self, arguments):
         self._imports()
         self.db = arguments.pop('db', 0)
         self.distributed_lock = arguments.get('distributed_lock', False)
 
-        #self.lock_timeout = arguments.get('lock_timeout', None)
-        #self.lock_sleep = arguments.get('lock_sleep', 0.1)
+        self.lock_timeout = arguments.get('lock_timeout', None)
+        self.lock_sleep = arguments.get('lock_sleep', 0.1)
 
         self.redis_expiration_time = arguments.pop('redis_expiration_time', 0)
         self.client = self._create_client()
 
     def get_mutex(self, key):
         if self.distributed_lock:
-            return RedisLock(lambda: self.client, key)
-
-            # TODO: see if we can use this lock, however it is
-            # deadlocking in unit tests right now
-            # return self.client.lock(u"_lock{}".format(key), self.lock_timeout,
-            #                        self.lock_sleep)
+            return self.client.lock(u"_lock{}".format(key), self.lock_timeout,
+                                    self.lock_sleep)
         else:
             return None
 
     def delete_multi(self, keys):
         self.client.delete(*keys)
 
-
-class RedisLock(object):
-    """Simple distributed lock using Redis.
-
-    This is an adaptation of the memcached lock featured at
-    http://amix.dk/blog/post/19386
-
-    """
-    def __init__(self, client_fn, key):
-        self.client_fn = client_fn
-        self.key = "_lock" + key
-
-    def acquire(self, wait=True):
-        client = self.client_fn()
-        i = 0
-        while True:
-            if client.setnx(self.key, 1):
-                return True
-            elif not wait:
-                return False
-            else:
-                sleep_time = (((i + 1) * random.random()) + 2 ** i) / 2.5
-                time.sleep(sleep_time)
-            if i < 15:
-                i += 1
-
-    def release(self):
-        client = self.client_fn()
-        client.delete(self.key)
-
-

File dogpile/cache/proxy.py

 of different backends without altering the class itself or having to extend the
 base backend.
 
-.. versionadded:: 0.4.4  Added support for the :class:`.ProxyBackend` class.
+.. versionadded:: 0.5.0  Added support for the :class:`.ProxyBackend` class.
 
 """
 
     the next proxy in the chain that a method can be
     delegated towards.
 
-    .. versionadded:: 0.4.4
+    .. versionadded:: 0.5.0
 
     """