diff options
author | andy <andy@whiskeymedia.com> | 2012-08-14 14:34:23 -0700 |
---|---|---|
committer | andy <andy@whiskeymedia.com> | 2012-08-14 14:34:23 -0700 |
commit | cdebbd48771f49a7cdf68823dcfc487ea15141cf (patch) | |
tree | 9a1bf424b9fa662c922b1050d708a75dd0455337 /redis/utils.py | |
parent | 937f8e4dfecc838afcc208a86c5d5139b33626fd (diff) | |
parent | a378cdb91fbf3909b67748bc18a12f0dbbcaacf5 (diff) | |
download | redis-py-cdebbd48771f49a7cdf68823dcfc487ea15141cf.tar.gz |
Merge remote-tracking branch 'jparise/cls-from_url'
Conflicts:
redis/client.py
redis/utils.py
Diffstat (limited to 'redis/utils.py')
-rw-r--r-- | redis/utils.py | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/redis/utils.py b/redis/utils.py index a9fe83b..20cef6c 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -1,31 +1,9 @@ from redis.client import Redis -from redis._compat import urlparse -DEFAULT_DATABASE_ID = 0 - - -def from_url(url, db=None): +def from_url(url, db=None, **kwargs): """Returns an active Redis client generated from the given database URL. Will attempt to extract the database id from the path url fragment, if none is provided. """ - - url = urlparse(url) - - # Make sure it's a redis database. - if url.scheme: - assert url.scheme == 'redis' - - # Attempt to resolve database id. - if db is None: - try: - db = int(url.path.replace('/', '')) - except (AttributeError, ValueError): - db = DEFAULT_DATABASE_ID - - return Redis( - host=url.hostname, - port=url.port, - db=db, - password=url.password) + return Redis.from_url(url, db, **kwargs) |