1. Mike Bayer
  2. dogpile.cache

Commits

Mike Bayer  committed 99ba222

- repair redis connect arguments and tests, including broken tests
from pr 16, add new test for pr 17.

  • Participants
  • Parent commits 9cb1c70
  • Branches master

Comments (0)

Files changed (2)

File dogpile/cache/backends/redis.py

View file
             # options present within, so here we disregard socket_timeout
             # and others.
             return redis.StrictRedis(connection_pool=self.connection_pool)
-        elif self.url is not None:
-            return redis.StrictRedis.from_url(url=self.url,
-                    socket_timeout=self.socket_timeout)
+
+        args = {}
+        if self.socket_timeout:
+            args['socket_timeout'] = self.socket_timeout
+
+        if self.url is not None:
+            args.update(url=self.url)
+            return redis.StrictRedis.from_url(**args)
         else:
-            return redis.StrictRedis(host=self.host, password=self.password,
-                    port=self.port, db=self.db,
-                    socket_timeout=self.socket_timeout)
+            args.update(
+                host=self.host, password=self.password,
+                port=self.port, db=self.db
+            )
+            return redis.StrictRedis(**args)
+
 
     def get_mutex(self, key):
         if self.distributed_lock:

File tests/cache/test_redis_backend.py

View file
 from ._fixtures import _GenericBackendTest, _GenericMutexTest
 from unittest import TestCase
 from nose import SkipTest
-from mock import patch
+from mock import patch, Mock
 
 class _TestRedisConn(object):
     @classmethod
         arguments = {
             'host': '127.0.0.1',
             'port': 6379,
-            'socket_timeout': 0.5
+            'socket_timeout': 0.5,
+            'password': None,
+            'db': 0,
             }
         self._test_helper(MockStrictRedis, arguments)
 
+    def test_connect_with_connection_pool(self, MockStrictRedis):
+        pool = Mock()
+        arguments = {
+            'connection_pool': pool,
+            'socket_timeout': 0.5
+            }
+        expected_args = {'connection_pool': pool}
+        self._test_helper(MockStrictRedis, expected_args,
+                connection_args=arguments)
+
     def test_connect_with_url(self, MockStrictRedis):
         arguments = {
             'url': 'redis://redis:password@127.0.0.1:6379/0'