Added ability to specify the redis connection parameter as an URL. Fixes #26.

This commit is contained in:
Jannis Leidel 2013-02-21 19:00:12 +01:00
parent c2c64f7d44
commit 21344d9168
2 changed files with 8 additions and 1 deletions

View file

@ -69,6 +69,10 @@ The is the default backend and has a couple of options:
'db': 0,
}
Alternatively you can use a URL to do the same::
CONSTANCE_REDIS_CONNECTION = 'redis://username:password@localhost:6379/0'
* ``CONSTANCE_REDIS_CONNECTION_CLASS``
An (optional) dotted import path to a connection to use, e.g.::

View file

@ -25,7 +25,10 @@ class RedisBackend(Backend):
except ImportError:
raise ImproperlyConfigured(
"The Redis backend requires redis-py to be installed.")
self._rd = redis.Redis(**settings.REDIS_CONNECTION)
if isinstance(settings.REDIS_CONNECTION, basestring):
self._rd = redis.from_url(settings.REDIS_CONNECTION)
else:
self._rd = redis.Redis(**settings.REDIS_CONNECTION)
def add_prefix(self, key):
return "%s%s" % (self._prefix, key)