Commits

Mike Bayer committed d389ffc

- changelog, some cleanup

Comments (0)

Files changed (4)

docs/build/changelog.rst

 ==============
 Changelog
 ==============
+.. changelog::
+    :version: 0.4.1
+
+    .. change:
+        :tags: feature
+
+      Redis backend now accepts optional "url" argument,
+      will be passed to the new ``StrictRedis.from_url()``
+      method to determine connection info.  Courtesy
+      inklesspen.
 
 .. changelog::
     :version: 0.4.0

dogpile/cache/__init__.py

-__version__ = '0.4.0'
+__version__ = '0.4.1'
 
 from .region import CacheRegion, register_backend, make_region

dogpile/cache/backends/redis.py

 import random
 import time
 
+redis = None
+
 __all__ = 'RedisBackend', 'RedisLock'
 
 class RedisBackend(CacheBackend):
 
     Arguments accepted in the arguments dictionary:
 
-    :param url: string. If provided, will override separate host/port/db params.
+    :param url: string. If provided, will override separate host/port/db
+     params.  The format is that accepted by ``StrictRedis.from_url()``.
+
+     .. versionadded:: 0.4.1
 
     :param host: string, default is ``localhost``.
 
         import redis
 
     def _create_client(self):
-        # creates client instace (so test harness can test connection)
         if self.url is not None:
             return redis.StrictRedis.from_url(url=self.url)
-        return redis.StrictRedis(host=self.host, password=self.password, port=self.port, db=self.db)
+        else:
+            return redis.StrictRedis(host=self.host, password=self.password,
+                                        port=self.port, db=self.db)
 
     def get_mutex(self, key):
         if self.distributed_lock:
             elif not wait:
                 return False
             else:
-                sleep_time = (((i+1)*random.random()) + 2**i) / 2.5
+                sleep_time = (((i + 1) * random.random()) + 2 ** i) / 2.5
                 time.sleep(sleep_time)
             if i < 15:
                 i += 1

tests/cache/test_redis_backend.py

 class RedisTest(_TestRedisConn, _GenericBackendTest):
     backend = 'dogpile.cache.redis'
     config_args = {
-        "arguments":{
+        "arguments": {
             'host': '127.0.0.1',
             'port': 6379,
             'db': 0,
 class RedisDistributedMutexTest(_TestRedisConn, _GenericMutexTest):
     backend = 'dogpile.cache.redis'
     config_args = {
-        "arguments":{
+        "arguments": {
             'host': '127.0.0.1',
             'port': 6379,
             'db': 0,
 
 @patch('redis.StrictRedis', autospec=True)
 class RedisConnectionTest(TestCase):
+    backend = 'dogpile.cache.redis'
+
     @classmethod
     def setup_class(cls):
         try:
-            global redis
-            import redis
+            cls.backend_cls = _backend_loader.load(cls.backend)
+            cls.backend_cls({})
         except ImportError:
-            raise SkipTest("Redis library not installed")
-
-        cls.backend_cls = _backend_loader.load('dogpile.cache.redis')
+            raise SkipTest("Backend %s not installed" % cls.backend)
 
     def _test_helper(self, mock_obj, expected_args, connection_args=None):
         if connection_args is None:
             # The redis backend pops items from the dict, so we copy
             connection_args = expected_args.copy()
 
-        backend = self.backend_cls(connection_args)
+        self.backend_cls(connection_args)
         mock_obj.assert_called_once_with(**expected_args)
 
     def test_connect_with_defaults(self, MockStrictRedis):
             'db': 0,
             }
         self._test_helper(MockStrictRedis, arguments)
-        
+
     def test_connect_with_url(self, MockStrictRedis):
         arguments = {
             'url': 'redis://redis:password@127.0.0.1:6379/0'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.