summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaulius Menkevičius <saulius.menkevicius@gmail.com>2014-05-28 14:46:20 +0300
committerSaulius Menkevičius <saulius.menkevicius@gmail.com>2014-05-28 14:58:28 +0300
commit65cfbeb3be62f485551448cb56351860c3a97b19 (patch)
tree4906c39cc570ba9c5c5c61a326a6cc80d8388699
parent30685d06840e18f28e7c88d1bc251e7e5e8a130d (diff)
downloaddogpile-cache-65cfbeb3be62f485551448cb56351860c3a97b19.tar.gz
dogpile/cache/backends/redis.py: add support for the 'socket_timeout' parameter
-rw-r--r--dogpile/cache/backends/redis.py7
-rw-r--r--tests/cache/test_redis_backend.py10
2 files changed, 14 insertions, 3 deletions
diff --git a/dogpile/cache/backends/redis.py b/dogpile/cache/backends/redis.py
index 3080ca0..9766201 100644
--- a/dogpile/cache/backends/redis.py
+++ b/dogpile/cache/backends/redis.py
@@ -66,6 +66,8 @@ class RedisBackend(CacheBackend):
Redis should expire it. This argument is only valid when
``distributed_lock`` is ``True``.
+ :param socket_timeout: float, seconds for socket timeout. Default is None (no timeout).
+
.. versionadded:: 0.5.0
:param lock_sleep: integer, number of seconds to sleep when failed to
@@ -84,6 +86,7 @@ class RedisBackend(CacheBackend):
self.port = arguments.pop('port', 6379)
self.db = arguments.pop('db', 0)
self.distributed_lock = arguments.get('distributed_lock', False)
+ self.socket_timeout = arguments.pop('socket_timeout', None)
self.lock_timeout = arguments.get('lock_timeout', None)
self.lock_sleep = arguments.get('lock_sleep', 0.1)
@@ -98,10 +101,10 @@ class RedisBackend(CacheBackend):
def _create_client(self):
if self.url is not None:
- return redis.StrictRedis.from_url(url=self.url)
+ return redis.StrictRedis.from_url(url=self.url, socket_timeout=self.socket_timeout)
else:
return redis.StrictRedis(host=self.host, password=self.password,
- port=self.port, db=self.db)
+ port=self.port, db=self.db, socket_timeout=self.socket_timeout)
def get_mutex(self, key):
if self.distributed_lock:
diff --git a/tests/cache/test_redis_backend.py b/tests/cache/test_redis_backend.py
index 7f2729b..d6dddc6 100644
--- a/tests/cache/test_redis_backend.py
+++ b/tests/cache/test_redis_backend.py
@@ -89,8 +89,16 @@ class RedisConnectionTest(TestCase):
}
self._test_helper(MockStrictRedis, arguments)
+ def test_connect_with_socket_timeout(self, MockStrictRedis):
+ arguments = {
+ 'host': '127.0.0.1',
+ 'port': 6379,
+ 'socket_timeout': 0.5
+ }
+ self._test_helper(MockStrictRedis, arguments)
+
def test_connect_with_url(self, MockStrictRedis):
arguments = {
'url': 'redis://redis:password@127.0.0.1:6379/0'
}
- self._test_helper(MockStrictRedis.from_url, arguments) \ No newline at end of file
+ self._test_helper(MockStrictRedis.from_url, arguments)