summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-06-13 13:40:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-06-13 13:40:50 -0400
commit9cb1c7016738b703c593628851ffe33efb7e0852 (patch)
tree7dd18f9e3d7f1407c1d86e54e8f147d2d23e0c3c
parentd3bd9fbd81334819cd4dd38b367a87a6eb2bd7e1 (diff)
parent069f6e1b0e5d9445d9f91a2c6711d02d3a146296 (diff)
downloaddogpile-cache-9cb1c7016738b703c593628851ffe33efb7e0852.tar.gz
Merge https://bitbucket.org/masayuko/dogpile.cache/branch/master into pr/17
Conflicts: dogpile/cache/backends/redis.py
-rw-r--r--docs/build/changelog.rst8
-rw-r--r--dogpile/cache/backends/redis.py23
2 files changed, 28 insertions, 3 deletions
diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst
index 45e07c3..25f32d9 100644
--- a/docs/build/changelog.rst
+++ b/docs/build/changelog.rst
@@ -6,6 +6,14 @@ Changelog
.. change::
:tags: feature
+ :pullreq: 17
+
+ Added new :paramref:`.RedisBackend.connection_pool` option
+ on the Redis backend; this can be passed a ``redis.ConnectionPool``
+ instance directly. Pull request courtesy Masayuko.
+
+ .. change::
+ :tags: feature
:pullreq: 16
Added new :paramref:`.RedisBackend.socket_timeout` option
diff --git a/dogpile/cache/backends/redis.py b/dogpile/cache/backends/redis.py
index c5663cb..e8b9969 100644
--- a/dogpile/cache/backends/redis.py
+++ b/dogpile/cache/backends/redis.py
@@ -79,6 +79,15 @@ class RedisBackend(CacheBackend):
.. versionadded:: 0.5.0
+ :param connection_pool: ``redis.ConnectionPool`` object. If provided,
+ this object supersedes other connection arguments passed to the
+ ``redis.StrictRedis`` instance, including url and/or host as well as
+ socket_timeout, and will be passed to ``redis.StrictRedis`` as the
+ source of connectivity.
+
+ .. versionadded:: 0.5.4
+
+
"""
def __init__(self, arguments):
@@ -95,6 +104,7 @@ class RedisBackend(CacheBackend):
self.lock_sleep = arguments.get('lock_sleep', 0.1)
self.redis_expiration_time = arguments.pop('redis_expiration_time', 0)
+ self.connection_pool = arguments.get('connection_pool', None)
self.client = self._create_client()
def _imports(self):
@@ -103,11 +113,18 @@ class RedisBackend(CacheBackend):
import redis
def _create_client(self):
- if self.url is not None:
- return redis.StrictRedis.from_url(url=self.url, socket_timeout=self.socket_timeout)
+ if self.connection_pool is not None:
+ # the connection pool already has all other connection
+ # 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)
else:
return redis.StrictRedis(host=self.host, password=self.password,
- port=self.port, db=self.db, socket_timeout=self.socket_timeout)
+ port=self.port, db=self.db,
+ socket_timeout=self.socket_timeout)
def get_mutex(self, key):
if self.distributed_lock: