From 21344d9168c1de6d66cb1e3f4eca6175b2cc9bcd Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 21 Feb 2013 19:00:12 +0100 Subject: [PATCH] Added ability to specify the redis connection parameter as an URL. Fixes #26. --- README.rst | 4 ++++ constance/backends/redisd.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 433d888..edb4aa3 100644 --- a/README.rst +++ b/README.rst @@ -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.:: diff --git a/constance/backends/redisd.py b/constance/backends/redisd.py index e512f0b..b023e38 100644 --- a/constance/backends/redisd.py +++ b/constance/backends/redisd.py @@ -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)